Connection Property error

  • Thread starter Thread starter Taishi
  • Start date Start date
T

Taishi

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.
 
Hello T.
You need to assign the ConnectionString property of your
command cmdStores.

Kind Regards
Jorge
 
Jorge,

I think I did that. In the Form view, 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

You said the Connection String. I am looking at the Connection Property.

Where is the Connection String Property of the cmdStores located?
Will please give me a step-by-step?

Thanks,

T.
 
P.S. Just my opinion, if your using the objects from the data tab of
the toolbox... Stop!!!!!! Learn to do it, totally in code, no objects.
 
Are you using the objects from the data tab on the toolbox. ?

If you are... Did you set the properties via the property manager...
Look under 'Web Form Designer Generated Code' section of your
code-behind.

From your code, your not settng your connection string, unless you've
set it via the property manager of the sqlconnection object.

One other thing, Why are you executing a sqlreader, binding it to a
datasource then closing the sqlreader.
If your wanting to use a disconnected datasource, use a datatable or
dataset, and close the connection, not the source of your data.
 
I'm having hard time understanding the terminology. I don't know coding.
Please use examples.

OK. I set the CONNECTION STRING via the Properties Manager(i'm calling it
just Properties). The steps:
Properties of conPubs
click the +DynamicProperties
click the ConnectionString ... (3 dots)

Properties of cmdStores
cmdStores (added from the Data/Toolbox)
click the +Connection(not the plus sign but the drop down box)
selected conPubs

Will you please give me examples from my code?
What is my datasource?

Why is my program still showing the same error?

Thanks in advance for the help,
T.

Terry Williams said:
P.S. Just my opinion, if your using the objects from the data tab of
the toolbox... Stop!!!!!! Learn to do it, totally in code, no objects.
I'll stop when I'm more experienced. Or someone shows me how.
 
I'm proberly not the right person to be teaching over the internet, and
it would take forever for me to try. Not that I don't want to, but one
of us, would be pulling our hair out soon.

But I understand what level your at now.

Most books always teach database programming from the standpoint of
using the objects in the toolbox. I'm totally against it.

I started programming using a language called Databus on Datapoint
systems. It's now called PL/B. There was no visual development
environment (laugh), just a good old text editor.

Is there anyone that could suggest a book for Taishi, that leans more
toward a pure coding standpoint.
 
It's just a 15 line program that I can not get to work.

It want take that long. Maby 1 to 2 responses.

Reading a book is different from receiving quality tips from a professional.

Taishi
 
What's your connection string ?

Type type of component is ddlStores ? Just so I know..

It a combobox/Dropdownlist, which I assume it is.

Here is some of my Code as a demonstration using a dropdownlist. It
works, tested it out. Again DropDownList1 is a dropdownlist :) Fill in
the connectionstring and commandstring with your values and you are
ready to go.


If (Not IsPostBack) Then
Dim myDataReader As SqlClient.SqlDataReader
Dim MyConnection As New
SqlClient.SqlConnection("server=127.0.0.1;UID=sa;PWD=symantec;database=t
erryw6_jobs")
Dim MyCommand As New SqlClient.SqlCommand("Select DeptID
from Departments", MyConnection)
MyConnection.Open()

myDataReader = MyCommand.ExecuteReader

DropDownList1.DataSource = myDataReader
DropDownList1.DataTextField = "DeptID"
DropDownList1.DataValueField = "DeptID"
DropDownList1.DataBind()

MyConnection.Close()

End If
 
Terry,

Thanks for tutoring me. The hair pulling is gonna come from me not knowing
code. Trying to convert your code into the FORM Design.

My problem is sort of fixed. I did not close my MyConnection.

Now, I just have a blank list box. awuugghhh.. banging my head.

In the Properties for MyConnection I have the following as my Connection
String:

workstation id=MyMachineName;packet size=4096;integrated security=SSPI;data
source="MyMachineName\vsdotnet";attachdbfilename="D:\Program Files\Microsoft
SQL Server\MSSQL$NETSDK\Data\pubs.mdf";persist security info=False;initial
catalog=pubs

In the Properties for MyCommand I have the following as my Connection
String:

workstation id=MyMachineName;packet size=4096;integrated security=SSPI;data
source="MyMachineName\vsdotnet";attachdbfilename="D:\Program Files\Microsoft
SQL Server\MSSQL$NETSDK\Data\pubs.mdf";persist security info=False;initial
catalog=pubs

I'm trying to grasp the concept but it's frustrating.

Thanks,
T.
 
Back
Top