Possible Duplicate:
Is there any need to close a DbConnection if a using clause is used?
Does OledbConnection.Dispose() close the connection?
I am aware that SqlConnection does but what about OledbConnection?
Possible Duplicate:
Is there any need to close a DbConnection if a using clause is used?
Does OledbConnection.Dispose() close the connection?
I am aware that SqlConnection does but what about OledbConnection?
Yes, it also does.
Source: OleDbConnection.Dispose Method (Boolean)
The Dispose method calls Close, and removes the OleDbConnection from the connection pool.
For detailed information see the Remarks section on the reference link to know about the case of releasing both managed and unmanaged resources.
Yes, according to the documentation on MSDN http://msdn.microsoft.com/en-us/library/aa325890(v=vs.71).aspx , OleDbConnection.Dispose() also does call the OleDbConnection.Close().
Yes it does MSDN:
The Dispose method calls Close, and removes the OleDbConnection from the connection pool.
Note, that the above is from the .NET Framework 1.1. But (in this case) you can count on things having not changed.
Also, you can be almost 100% sure that every class that implements IDbConnection will "close" the connection in the Dispose method - whatever that means for the particular implementation is not relevant, but it will be equivalent to calling Close manually.
Every implementation that does not behave that way, should be IMO considered broken.
Here is the ultimate proof.. the actual code of the Dispose method, taken using a reflector:
// System.Data.OleDb.OleDbConnection
protected override void Dispose(bool disposing)
{
if (disposing)
{
this._userConnectionOptions = null;
this._poolGroup = null;
this.Close();
}
this.DisposeMe(disposing);
base.Dispose(disposing);
}
Yes. If it didn't, then it can't fully dispose of it's resources. BinaryReader, BinaryWriter, etc all close the underlying stream as well