M
MarkusJNZ
Hi, I have a DataReader which I think may be the cause of connections
remaining open to a MSSQL database.
basically the pseudo code is below
======
SqlConnection conn = new SqlConnection("connectionString");
SqlCommand cmd = new SqlCommand("Select * from blah",conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
// do something
}
conn.Close();
======
Basically, the code closes the connection object but does not close the
acutal dataReader.
Does closing the database connection *also* close the dataReader
connection and remove all references betweent the MSSQL database and
the ADO.NET objects?
Normally, I would do this, so I'm interested in the difference
======
SqlConnection conn = new SqlConnection("connectionString");
SqlCommand cmd = new SqlCommand("Select * from blah",conn);
conn.Open();
SqlDataReader reader =
cmd.ExecuteReader(CommandBehaviour.CloseConnection);
while(reader.Read())
{
// do something
}
reader.Close();
======
TIA Markus
remaining open to a MSSQL database.
basically the pseudo code is below
======
SqlConnection conn = new SqlConnection("connectionString");
SqlCommand cmd = new SqlCommand("Select * from blah",conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
// do something
}
conn.Close();
======
Basically, the code closes the connection object but does not close the
acutal dataReader.
Does closing the database connection *also* close the dataReader
connection and remove all references betweent the MSSQL database and
the ADO.NET objects?
Normally, I would do this, so I'm interested in the difference
======
SqlConnection conn = new SqlConnection("connectionString");
SqlCommand cmd = new SqlCommand("Select * from blah",conn);
conn.Open();
SqlDataReader reader =
cmd.ExecuteReader(CommandBehaviour.CloseConnection);
while(reader.Read())
{
// do something
}
reader.Close();
======
TIA Markus