System.Data.OleDb.OleDbConnection Class

Represents an open connection to a data source.

See Also: OleDbConnection Members


public sealed class OleDbConnection : System.Data.Common.DbConnection, ICloneable


An System.Data.OleDb.OleDbConnection object represents a unique connection to a data source. With a client/server database system, it is equivalent to a network connection to the server. Depending on the functionality supported by the native OLE DB provider, some methods or properties of an System.Data.OleDb.OleDbConnection object may not be available.

When you create an instance of System.Data.OleDb.OleDbConnection, all properties are set to their initial values. For a list of these values, see the System.Data.OleDb.OleDbConnection constructor.

You can open more than one DataReader on a single System.Data.OleDb.OleDbConnection. If the OLE DB provider you use does not support more than one DataReader on a single connection, the provider implicitly opens an additional connection for each.

If the System.Data.OleDb.OleDbConnection goes out of scope, it is not closed. Therefore, you must explicitly close the connection by calling OleDbConnection.Close or Dispose, or by using the System.Data.OleDb.OleDbConnection object within a Using statement.


To deploy high-performance applications, you must use connection pooling. When you use the .NET Framework Data Provider for OLE DB, you do not have to enable connection pooling because the provider manages this automatically. For more information about how to use connection pooling with the .NET Framework Data Provider for OLE DB, see Understanding Connection Pooling.

If a fatal System.Data.OleDb.OleDbException (for example, a SQL Server severity level of 20 or greater) is generated by the method executing an System.Data.OleDb.OleDbCommand, the System.Data.OleDb.OleDbConnection might be closed. However, the user can reopen the connection and continue.

An application that creates an instance of the System.Data.OleDb.OleDbConnection object can require all direct and indirect callers to have sufficient permission to the code by setting declarative or imperative security demands. System.Data.OleDb.OleDbConnection makes security demands using the System.Data.OleDb.OleDbPermission object. Users can verify that their code has sufficient permissions by using the System.Data.OleDb.OleDbPermissionAttribute object. Users and administrators can also use the Code Access Security Policy Tool (Caspol.exe) to modify security policy at the computer, user, and enterprise levels. For more information, see Code Access Security and ADO.NET.

For more information about handling warning and informational messages from the data server, see Working with Connection Events.


The System.Data.OleDb.OleDbConnection object does not support setting or retrieving dynamic properties specific to an OLE DB provider. Only properties that can be passed in the connection string for the OLE DB provider are supported.


Namespace: System.Data.OleDb
Assembly: System.Data (in System.Data.dll)
Assembly Versions: 1.0.3300.0, 1.0.5000.0,