Reputation: 153
I am using microsoft.entrprise.libraries in an asp.net app. I am calling LoadDataSet. The code below uses 'using' so this mean that all resources will be cleaned up once that call has completed.
What happens when a call is made to the db and it times out and an error is thrown in the app, will the connection be closed?
Thanks, Robert
public virtual void LoadDataSet(DbCommand command, DataSet dataSet, string[] tableNames)
{
using (var wrapper = GetOpenConnection())
{
PrepareCommand(command, wrapper.Connection);
DoLoadDataSet(command, dataSet, tableNames);
}
}
Upvotes: 1
Views: 177
Reputation: 492
The using
statement actually expands to something like the following, so yes, if wrapper's Dispose()
call releases all of the appropriate resources, then there is no leak (at least within the wrapper
object):
var wrapper = GetOpenConnection()
try
{
PrepareCommand(command, wrapper.Connection);
DoLoadDataSet(command, dataSet, tableNames);
}
finally
{
if (wrapper != null)
{
((IDisposable)wrapper ).Dispose();
}
}
Upvotes: 1