Do we need to call dbCommand.Dispose() ?
-
Hello ! I have a question about DB specifications : Do we have to call IDbCommand.Dispose ? What does IDbCommand.Dispose mean? We have problem doing this :
IDbConnction pipe = new OleDbConnection(connString); IDbCommand command = pipe.CreateCommand(); command.QueryString = "select ..."; IDataReader reader = command.ExecuteReader(); **command.Dispose();** reader.Close(); pipe.Close();
The problem get solved if we don't do IDbCommand.Dispose Your comments would be very helpful. Thanks. Sovann -
Hello ! I have a question about DB specifications : Do we have to call IDbCommand.Dispose ? What does IDbCommand.Dispose mean? We have problem doing this :
IDbConnction pipe = new OleDbConnection(connString); IDbCommand command = pipe.CreateCommand(); command.QueryString = "select ..."; IDataReader reader = command.ExecuteReader(); **command.Dispose();** reader.Close(); pipe.Close();
The problem get solved if we don't do IDbCommand.Dispose Your comments would be very helpful. Thanks. SovannYou cannot Dispose Command Object after ExecuteReader Method, the datareader object maintains the connection to the database as it will not pull all data at once, and it will pull data record by record. So dispose the command object after getting all the data.
Naveen G MCSD.Net
-
You cannot Dispose Command Object after ExecuteReader Method, the datareader object maintains the connection to the database as it will not pull all data at once, and it will pull data record by record. So dispose the command object after getting all the data.
Naveen G MCSD.Net
Thank you. Anyway, do we have to call IDbCommand.Dispose ?
-
Thank you. Anyway, do we have to call IDbCommand.Dispose ?
Whenever a class exposes a
Dispose
method you should definitely call it as it frees resources immediatly. You can take advantage of theusing
statement that automatically callsDispose
on an object when execution leaves its scope. Simple example taken from MSDN.using (Font font1 = new Font("Arial", 10.0f))
{
//use font1 object
}
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
Whenever a class exposes a
Dispose
method you should definitely call it as it frees resources immediatly. You can take advantage of theusing
statement that automatically callsDispose
on an object when execution leaves its scope. Simple example taken from MSDN.using (Font font1 = new Font("Arial", 10.0f))
{
//use font1 object
}
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
Thank you. Your comment has been very helpful :)