K
kempshall
When I use an SqlDataAdapter to fill a DataSet from a database, do I
need to explicitly open and close the SqlConnection that I'm using? For
example, I have code that looks like this:
SqlConnection myConnection = null;
try {
myConnection = new
SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlDataAdapter myDA = new SqlDataAdapter( sql, myConnection );
// myConnection.Open();
DataTable table = new DataTable();
myDA.Fill( table );
// myConnection.Close();
return table;
}
I'm particularly curious as to whether the SqlDataAdapter is guaranteed
to close automatically, because when I check my MSSQL process info
(after executing all my queries), I find a bunch of excess sleeping
processes and I'm not sure how they got created or why they haven't
been killed.
If anybody has some ideas or help, I'd really appreciate it.
Thanks,
Jay
need to explicitly open and close the SqlConnection that I'm using? For
example, I have code that looks like this:
SqlConnection myConnection = null;
try {
myConnection = new
SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlDataAdapter myDA = new SqlDataAdapter( sql, myConnection );
// myConnection.Open();
DataTable table = new DataTable();
myDA.Fill( table );
// myConnection.Close();
return table;
}
I'm particularly curious as to whether the SqlDataAdapter is guaranteed
to close automatically, because when I check my MSSQL process info
(after executing all my queries), I find a bunch of excess sleeping
processes and I'm not sure how they got created or why they haven't
been killed.
If anybody has some ideas or help, I'd really appreciate it.
Thanks,
Jay