tidydave
asked on
Invalid attempt to read when reader is closed
A colleague of mine is experiencing a very perplexing error.
He is using the following code to databind a datagrid:
Dim dbSearchReader As SqlDataReader = dbConnection.ConnectionStr ing = ConfigurationSettings.AppS ettings("C onnection" )
dbConnection.Open()
dbCommand = New SqlCommand(Session("SQL"), dbConnection)
dbSearchReader = dbCommand.ExecuteReader
dgProducts.DataSource = dbSearchReader
dgProducts.DataBind()
When he runs his program on localhost and the development server the datagrid binds correctly.
When he runs his program on the live server he gets the following error:
System.InvalidOperationExc eption: Invalid attempt to Read when reader is closed. at System.Data.SqlClient.SqlD ataReader. Read() at System.Data.Common.DbEnume rator.Move Next() at System.Web.UI.WebControls. DataGrid.C reateContr olHierarch y(Boolean useDataSource) at System.Web.UI.WebControls. BaseDataLi st.OnDataB inding(Eve ntArgs e) at System.Web.UI.WebControls. BaseDataLi st.DataBin d()
Any ideas are appreciated :-)
Thanks,
Dave.
He is using the following code to databind a datagrid:
Dim dbSearchReader As SqlDataReader = dbConnection.ConnectionStr
dbConnection.Open()
dbCommand = New SqlCommand(Session("SQL"),
dbSearchReader = dbCommand.ExecuteReader
dgProducts.DataSource = dbSearchReader
dgProducts.DataBind()
When he runs his program on localhost and the development server the datagrid binds correctly.
When he runs his program on the live server he gets the following error:
System.InvalidOperationExc
Any ideas are appreciated :-)
Thanks,
Dave.
>> Dim dbSearchReader As SqlDataReader = ...??
I don't think you pasted the correct code, can you paste it again?
I don't think you pasted the correct code, can you paste it again?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Not sure why it put an "=" after the first line of pasted code? Shall post again.
Dim dbSearchReader As SqlDataReader
dbConnection.ConnectionStr ing = ConfigurationSettings.AppS ettings("C onnection" )
dbConnection.Open()
dbCommand = New SqlCommand(Session("SQL"), dbConnection)
dbSearchReader = dbCommand.ExecuteReader
dgProducts.DataSource = dbSearchReader
dgProducts.DataBind()
Cheers for the comments so far.
Dim dbSearchReader As SqlDataReader
dbConnection.ConnectionStr
dbConnection.Open()
dbCommand = New SqlCommand(Session("SQL"),
dbSearchReader = dbCommand.ExecuteReader
dgProducts.DataSource = dbSearchReader
dgProducts.DataBind()
Cheers for the comments so far.
What are you doing right after that ?
Use a DataSet Instead.