0
votes

My connection is instantiated when I instantiate this.database like below, when I call ExecuteDataReader on this.database I am using try, catch... it opens the connection executes reader and returns a SqlDataReader object.

With all that said will the using statement below close my connection that was instantiated in another class without a using statement and no explicit call to dispose or close?

using (IDataReader reader = this.database.ExecuteDataReader(storedProcedure))
{
    if (reader.Read())
    {
       blah....
    }
}

Thanks

1

1 Answers

0
votes

As I know Using is just a short cut for the following, and it works only if the underlaying object is disposable...

try
{
    connection = new [...]
}
catch
{
}
finally
{
    connection.dispose()
}