Invalid attempt to call FieldCount when reader is closed

M

mark.norgate

Hi

I have a problem with a repeater and a data connection.

In my Page_Load, I have the following code:

Dim connectionString As String =
WebConfig.ConnectionString
Dim connection As SqlConnection = New
SqlConnection(connectionString)
Dim adapter As SqlDataAdapter = New
SqlDataAdapter("SELECT applicationID FROM pvtProductApplication WHERE
productID = " + Request.QueryString("prodId"), connection)
Dim dataSet As DataSet = New DataSet()
connection.Open()
adapter.Fill(dataSet)
ApplicationRepeater.DataSource = dataSet
ApplicationRepeater.DataBind() /* error here */
connection.Close()

and I have a ApplicationRepeater_ItemCreated that also opens a data
connection and closes it. The error is raised as indicated above.

Can someone please help??

Thanks, Mark
 
T

Teemu Keiski

Hi,

are these operations (this and the one in ItemCreated) sharing the same
connection object, which would get closed unexpectedly?

You don't need to optimize that way (sharing one connection on the page)
necessarily, since connection pooling in .NET will mostly take care of that
e.g it will get you connections efficiently and reuse them. Of course if
there could be numerous of conenction object creations, that's another thing

And with DataAdapters' you don't need to open the connection first before
calling Fill, it is opened for you.

Anyways, to give more exact advice, can you show the code in ItemCreated
using the connection?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top