Dispose() method permanently removes connection object from memory and the resource no longer exists for any further processing.
string constring = "Server=(local);Database=my; User Id=sa; Password=sa"; SqlConnection sqlcon = new SqlConnection(constring); sqlcon.Open(); // connection is open
try { // code here which will be execute } catch { // code will be execute when error occurred in try block } finally { sqlcon.Dispose(); // close and desroy the connection object }
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Dispose() method permanently removes connection object from memory and the resource no longer exists for any further processing.
string constring = "Server=(local);Database=my; User Id=sa; Password=sa";
SqlConnection sqlcon = new SqlConnection(constring);
sqlcon.Open(); // connection is open
try
{
// code here which will be execute
}
catch
{
// code will be execute when error occurred in try block
}
finally
{
sqlcon.Dispose(); // close and desroy the connection object
}