Difference between connection.close and connection.dispose using Asp.net Connection String ? for ex:
Globals.dr.Dispose();
Globals.dr.Close();
Difference between connection.close and connection.dispose using Asp.net Connection String ? for ex:
Globals.dr.Dispose();
Globals.dr.Close();
Dispose() automatically calls .Close for SqlConnection. So you can only call Dispose or better use the using statement in C#.
using (var con = new SqlConnection()...)
{
....
}
When using Dispose()
it automatically calls the Close()
method on the Connection
object
Close actually closes the open connection to database. but dispose will remove the connection object from memory. since sqlconnection implements Finalize/Dispose pattern if you dispose connection before closing it, then close method is automaticly called.
basically dispose is about memory and close is about connection :D