K
Ken H.
Hi, just wondering when is a connection really closed when I called
the Close() method on the SqlConnection object. The code below runs
without problem even though the SqlConnection is supposedly "closed!"
The DumpTable routine dumps the correct values.
String strConn =
"SERVER=localhost;DATABASE=Northwind;UID=sa;PWD=whatever";
SqlConnection sqlConn = new SqlConnection(strConn);
SqlCommand sqlCmd = new SqlCommand("CustOrdersDetail", sqlConn);
sqlCmd.CommandType = CommandType.StoredProcedure;
SqlParameter cmdParm = sqlCmd.Parameters.Add("@orderId",
SqlDbType.Int, 4);
cmdParm.Value = 10250;
SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlCmd);
DataTable sqlTable = new DataTable("orders");
sqlAdapter.Fill(sqlTable);
dumpTable( sqlTable );
// release resources...
sqlAdapter.Dispose();
sqlCmd.Connection.Close();
sqlCmd.Connection.Dispose(); // necessary?
Console.WriteLine( sqlCmd.Connection.State ); // prints "Closed"
cmdParm.Value = 10248;
sqlAdapter = new SqlDataAdapter(sqlCmd);
sqlTable = new DataTable("orders");
sqlAdapter.Fill(sqlTable);
dumpTable( sqlTable );
the Close() method on the SqlConnection object. The code below runs
without problem even though the SqlConnection is supposedly "closed!"
The DumpTable routine dumps the correct values.
String strConn =
"SERVER=localhost;DATABASE=Northwind;UID=sa;PWD=whatever";
SqlConnection sqlConn = new SqlConnection(strConn);
SqlCommand sqlCmd = new SqlCommand("CustOrdersDetail", sqlConn);
sqlCmd.CommandType = CommandType.StoredProcedure;
SqlParameter cmdParm = sqlCmd.Parameters.Add("@orderId",
SqlDbType.Int, 4);
cmdParm.Value = 10250;
SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlCmd);
DataTable sqlTable = new DataTable("orders");
sqlAdapter.Fill(sqlTable);
dumpTable( sqlTable );
// release resources...
sqlAdapter.Dispose();
sqlCmd.Connection.Close();
sqlCmd.Connection.Dispose(); // necessary?
Console.WriteLine( sqlCmd.Connection.State ); // prints "Closed"
cmdParm.Value = 10248;
sqlAdapter = new SqlDataAdapter(sqlCmd);
sqlTable = new DataTable("orders");
sqlAdapter.Fill(sqlTable);
dumpTable( sqlTable );