Implementing a Connection

Implementing a Connection

.NET Framework 1.1

The Connection object represents a database connection or similar resource, and is the starting point for users of a .NET Framework data provider. It is geared towards representing connections to database servers, though any entity with similar behavior can be exposed as an IDbConnection.

In your implementation, you must ensure that a Connection is created and opened before Commands can be executed. Ensure that your implementation requires clients to explicitly open and close connections, rather than having your implementation open and close connections implicitly for the client. Perform your security checks when the connection is obtained; requiring an existing connection for the other classes in your .NET Framework data provider will then ensure that security checks are always performed when working with your data source.

The properties of the desired connection will be represented as a connection string. It is strongly recommended that .NET Framework data providers support the ConnectionString property using the familiar name-value pair system defined by OLE DB. Wherever possible, providers should use the same names to refer to connection properties as those used by the SQL Server and OLE DB .NET Framework data providers. This helps to ensure uniformity across multiple providers. For more information, see SqlConnection.ConnectionString Property and the OLE DB Programmer's Guide in the MSDN library located at

Connection objects are often expensive to obtain, so you may want to consider pooling connections or other techniques to mitigate this expense.

The implementation of IDbConnection should include, at a minimum, two constructors: a default constructor, as well as one that takes a connection string.

The following topics contain sample code for an implementation of a Connection object.

For a sample Visual Basic implementation:

For a sample C# implementation:

See Also

Implementing a .NET Framework Data Provider | Sample .NET Framework Data Provider

© 2015 Microsoft