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.ConnectionString = ConfigurationSettings.AppSettings("Connection")
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.InvalidOperationException: Invalid attempt to Read when reader is closed. at System.Data.SqlClient.SqlDataReader.Read() at System.Data.Common.DbEnumerator.MoveNext() at System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource) at System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) at System.Web.UI.WebControls.BaseDataList.DataBind()
Hi there,
when you bind ( dgProducts.DataBind()), ADO.Net closes the Reader. So, the reason you are getting error is, may be, due to something else you are doing after DataBinding. something else is trying to access the Reader.
0
tidydaveAuthor Commented:
Not sure why it put an "=" after the first line of pasted code? Shall post again.
Dim dbSearchReader As SqlDataReader
dbConnection.ConnectionString = ConfigurationSettings.AppSettings("Connection")
dbConnection.Open()
dbCommand = New SqlCommand(Session("SQL"), dbConnection)
dbSearchReader = dbCommand.ExecuteReader
dgProducts.DataSource = dbSearchReader
dgProducts.DataBind()
The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.
One of a set of tools we're offering as a way of saying thank you for being a part of the community.
Use a DataSet Instead.