using {} with SQLConnection

  • Thread starter Thread starter Ron
  • Start date Start date
R

Ron

If I wrap a SQLConnection with a using (...){} block will the connection
automatically be closed if an exception occures? Or will I still need a try
block to catch the exception and close the connection?

Thanks,
Ron
 
Using the "using" (i know, i know) will close your database connection.

James
 
Hi Ron,

using is considered equal to try/finally. The SqlConnection will be disposed even if an exception occurs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top