Currently my code is constructed as follows.
using (var sqlCon = new SqlConnection(Context.ReturnDatabaseConnection()))
{
sqlCon.Open();
try
{
//Code here
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
sqlCon.Close();
}
}
Ideally from what I understand using the 'using' statement will take care of the connection being closed but I have my doubts due to what other people have said.
Thanks
NO need as object will automatically disposed when we use using
blocks. Go through this
http://msdn.microsoft.com/en-us/library/yh598w02.aspx
What is the C# Using block and why should I use it?
Hi just the using statement will be fine. It will dispose the object and generally requires less coding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With