N
NJC©\(TM\)
Hello Newsgroup,
In a typical way to execute a function performing a database operation (either
calling ExecuteScalar, ExecuteNonQuery, or ExecuteReader) referencing
System.Data.sqlClient, I am currently coding my functions as such;
using(sqlConnection sql_conn = new sqlConnection(conn_string))
{
using(sqlCommand sql_comm = CreateCommand(commandText, sql_conn))
{
conn.Open();
// Execute Function
} // sqlCommand
} // sqlConnection
Disposal of the Connection and Command is explicit.
What about (calling a custom Command creator function 'CreateCommand');
using(sqlCommand sql_comm = CreateCommand(commandText, new
sqlConnection(conn_string)))
{
sql_comm.Connection.Open();
// Execute Function
} // sqlCommand
Does the Connection get Disposed of, excepting sqlDataReader will close the
Connection if it's flagged to do so?
Does the Connection require explicit disposing in this case?
That is, 'sql_comm.Connection.Dispose();'
When Googling, does sqlCommand.Dispose() dispose sqlConnection, there are many
pages describing it the other way round, Connection disposing Commands.
Thanks and regards Newsgroup,
In a typical way to execute a function performing a database operation (either
calling ExecuteScalar, ExecuteNonQuery, or ExecuteReader) referencing
System.Data.sqlClient, I am currently coding my functions as such;
using(sqlConnection sql_conn = new sqlConnection(conn_string))
{
using(sqlCommand sql_comm = CreateCommand(commandText, sql_conn))
{
conn.Open();
// Execute Function
} // sqlCommand
} // sqlConnection
Disposal of the Connection and Command is explicit.
What about (calling a custom Command creator function 'CreateCommand');
using(sqlCommand sql_comm = CreateCommand(commandText, new
sqlConnection(conn_string)))
{
sql_comm.Connection.Open();
// Execute Function
} // sqlCommand
Does the Connection get Disposed of, excepting sqlDataReader will close the
Connection if it's flagged to do so?
Does the Connection require explicit disposing in this case?
That is, 'sql_comm.Connection.Dispose();'
When Googling, does sqlCommand.Dispose() dispose sqlConnection, there are many
pages describing it the other way round, Connection disposing Commands.
Thanks and regards Newsgroup,