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;integrated
security=SSPI;database=northwind");
SqlCommand mySelSqlCommand = new SqlCommand("Select * from
Customers", myConnection);
try
{
myConnection.Open();
SqlDataReader myReader = mySelSqlCommand.ExecuteReader();
Response.Write(" Data Reader is Closed ?(after
Retrieveing)" + myReader.IsClosed.ToString());
DataGrid1.DataSource = myReader;
DataGrid1.DataBind();
Response.Write("Data Reader is Closed ?(after DataBind)" +
myReader.IsClosed.ToString());
myReader.Close();
Response.Write(""Data Reader is Closed ?(after Closing)" +
myReader.IsClosed.ToString());
}
catch(SqlException se)
{
Response.Write("Error : " + se.ToString());
}
finally
{
myConnection.Close();
}
// Code in the page load -Ends
Thanks
Ashish M Bhonkiya
"Trinath" <an*******@discussions.microsoft.com> wrote in message
news:FC**********************************@microsof t.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.