Hi Trinath,
Can you check datareader's IsClosed property and confirm if the reader
object gets closed after the databind method on the datagrid.
I have tried this leme know if i am doing something wrong here.
// Code in the page load
SqlConnection myConnection = new
SqlConnection(" server=ISC1XR\\ EINSTIEN;integr ated
security=SSPI;d atabase=northwi nd");
SqlCommand mySelSqlCommand = new SqlCommand("Sel ect * from
Customers", myConnection);
try
{
myConnection.Op en();
SqlDataReader myReader = mySelSqlCommand .ExecuteReader( );
Response.Write( " Data Reader is Closed ?(after
Retrieveing)" + myReader.IsClos ed.ToString());
DataGrid1.DataS ource = myReader;
DataGrid1.DataB ind();
Response.Write( "Data Reader is Closed ?(after DataBind)" +
myReader.IsClos ed.ToString());
myReader.Close( );
Response.Write( ""Data Reader is Closed ?(after Closing)" +
myReader.IsClos ed.ToString());
}
catch(SqlExcept ion se)
{
Response.Write( "Error : " + se.ToString());
}
finally
{
myConnection.Cl ose();
}
// Code in the page load -Ends
Thanks
Ashish M Bhonkiya
"Trinath" <an*******@disc ussions.microso ft.com> wrote in message
news:FC******** *************** ***********@mic rosoft.com...
Hi Joel,
DataBind does close the datareader.
You can verify this:
Datareader uses connected model (i.e.) as long as the datareader is open
you can't use the same connection object for other purposes. This will result in an Exception.
But after doing a DataBind (without closing the datareader) if you try to
use the connection object , it doesn't raise any exception. Well this means that the data reader is closed and connection is free to
be used for other things.