Groups | Blog | Home
all groups > vb.net controls > february 2004 >

vb.net controls : Connection Property error


Taishi
2/11/2004 12:03:12 PM
ExecuteReader: Connection property has not been initialized.

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidOperation Exception: ExecuteReader:
Connection property has not been initialized.

Source Error:

Line 142:
Line 143: drStores = cmdStores.ExecuteReader()
Line 144: ddlStores.DataSource = drStores
Line 145: ddlStores.DataTextField = "stor_name"


Any suggestions on how to resolve this error?

Thanks,
T.


Taishi
2/11/2004 3:11:12 PM
Suresh,

VS.Net
VB.Net

I was in the Form view and I notice that the cmdStores Connection Property
was set to conPubs. After the program is ran, the Connection Property
changes back to none. Here is my code:

Dim drStores As SqlClient.SqlDataReader

If Not IsPostBack Then

conPubs.Open()

drStores = cmdStores.ExecuteReader()

ddlStores.DataSource = drStores

ddlStores.DataTextField = "stor_name"

ddlStores.DataBind()

drStores.Close()

End If

End Sub



Thanks,

T.

[quoted text, click to view]
cmdStores object prior to executing this line drStores =
cmdStores.ExecuteReader().
[quoted text, click to view]

sstein NO[at]SPAM online.microsoft.com (
2/16/2004 7:37:17 PM
Taishi-

You need to Open the connection before calling ExecuteReader.

You should also Close the connection when done...


Steve Stein
VB Team

This posting is provided "AS IS" with no warranties and confers no rights.


--------------------
[quoted text, click to view]
microsoft.public.certification.visualstudio,microsoft.public.dotnet.framewor
k,microsoft.public.dotnet.framework.aspnet,microsoft.public.dotnet.languages
.vb,microsoft.public.dotnet.languages.vb.controls,microsoft.public.vstudio.d
evelopment
[quoted text, click to view]
cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGXS01.phx.gbl!TK2MSFTNGXA0
5.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
[quoted text, click to view]
microsoft.public.dotnet.framework.aspnet:209348
microsoft.public.dotnet.languages.vb:180549
microsoft.public.dotnet.languages.vb.controls:3984
microsoft.public.vstudio.development:4332
microsoft.public.certification.visualstudio:3769
[quoted text, click to view]
Taishi
2/17/2004 10:16:57 AM
Thanks Steven.

I also found another problem. I had a DataSet defined in the Form and in
the code.

It's working!! Finally!!!

Why can't you have it defined in both places?

T.

[quoted text, click to view]

sstein NO[at]SPAM online.microsoft.com (
2/23/2004 6:26:50 PM
Hi Taishi-

The dataset on your form is the same dataset that is declared in code. The
form designer and controls are a visual representation of the code.


Steve Stein

VB Team
This posting is provided "AS IS" with no warranties and confers no rights.

-------------------
[quoted text, click to view]
cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGXS01.phx.gbl!TK2MSFTNGXA0
5.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
[quoted text, click to view]
AddThis Social Bookmark Button