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.
 
Back
Top