DbConnection Class

Definition

Defines the core behavior of database connections and provides a base class for database-specific connections.

public ref class DbConnection abstract : IDisposable
public ref class DbConnection abstract : System::ComponentModel::Component, IAsyncDisposable, IDisposable, System::Data::IDbConnection
public ref class DbConnection abstract : IDisposable, System::Data::IDbConnection
public ref class DbConnection abstract : System::ComponentModel::Component, IDisposable, System::Data::IDbConnection
public ref class DbConnection abstract : System::ComponentModel::Component, System::Data::IDbConnection
public ref class DbConnection abstract : System::ComponentModel::Component, IAsyncDisposable, System::Data::IDbConnection
public abstract class DbConnection : IDisposable
public abstract class DbConnection : System.ComponentModel.Component, IAsyncDisposable, IDisposable, System.Data.IDbConnection
public abstract class DbConnection : IDisposable, System.Data.IDbConnection
public abstract class DbConnection : System.ComponentModel.Component, IDisposable, System.Data.IDbConnection
public abstract class DbConnection : System.ComponentModel.Component, System.Data.IDbConnection
public abstract class DbConnection : System.ComponentModel.Component, IAsyncDisposable, System.Data.IDbConnection
type DbConnection = class
    interface IDisposable
type DbConnection = class
    inherit Component
    interface IDbConnection
    interface IDisposable
    interface IAsyncDisposable
type DbConnection = class
    interface IDbConnection
    interface IDisposable
type DbConnection = class
    inherit Component
    interface IDbConnection
    interface IDisposable
Public MustInherit Class DbConnection
Implements IDisposable
Public MustInherit Class DbConnection
Inherits Component
Implements IAsyncDisposable, IDbConnection, IDisposable
Public MustInherit Class DbConnection
Implements IDbConnection, IDisposable
Public MustInherit Class DbConnection
Inherits Component
Implements IDbConnection, IDisposable
Public MustInherit Class DbConnection
Inherits Component
Implements IDbConnection
Public MustInherit Class DbConnection
Inherits Component
Implements IAsyncDisposable, IDbConnection
Inheritance
DbConnection
Inheritance
Derived
Implements

Notes to Implementers

When you inherit from DbConnection, you must override the following members: Close(), BeginDbTransaction(IsolationLevel), ChangeDatabase(String), CreateDbCommand(), Open(), and StateChange. You must also provide the following properties: ConnectionString, Database, DataSource, ServerVersion, and State.

Constructors

DbConnection()

Initializes a new instance of the DbConnection class.

Properties

CanCreateBatch

Gets a value that indicates whether this DbConnection instance supports the DbBatch class.

CanRaiseEvents

Gets a value indicating whether the component can raise an event.

(Inherited from Component)
ConnectionString

When overridden in a derived class, gets or sets the string used to open the connection.

ConnectionTimeout

Gets the time to wait (in seconds) while establishing a connection before terminating the attempt and generating an error.

Container

Gets the IContainer that contains the Component.

(Inherited from Component)
Database

When overridden in a derived class, gets the name of the current database after a connection is opened, or the database name specified in the connection string before the connection is opened.

DataSource

When overridden in a derived class, gets the name of the database server to which to connect.

DbProviderFactory

Gets the DbProviderFactory for this DbConnection.

DesignMode

Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
Events

Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
ServerVersion

When overridden in a derived class, gets a string that represents the version of the server to which the object is connected.

Site

Gets or sets the ISite of the Component.

(Inherited from Component)
State

Gets a string that describes the state of the connection.

Methods

BeginDbTransaction(IsolationLevel)

When overridden in a derived class, starts a database transaction.

BeginDbTransactionAsync(IsolationLevel, CancellationToken)

Asynchronously starts a database transaction.

BeginTransaction()

Starts a database transaction.

BeginTransaction(IsolationLevel)

Starts a database transaction with the specified isolation level.

BeginTransactionAsync(CancellationToken)

Asynchronously begins a database transaction.

BeginTransactionAsync(IsolationLevel, CancellationToken)

Asynchronously begins a database transaction.

ChangeDatabase(String)

When overridden in a derived class, changes the current database for an open connection.

ChangeDatabaseAsync(String, CancellationToken)

Asynchronously changes the current database for an open connection.

Close()

When overridden in a derived class, closes the connection to the database.

CloseAsync()

Asynchronously closes the connection to the database.

CreateBatch()

Returns a new instance of the provider's class that implements the DbBatch class.

CreateCommand()

Creates and returns a DbCommand object associated with the current connection.

CreateDbBatch()

When overridden in a derived class, returns a new instance of the provider's class that implements the DbBatch class.

CreateDbCommand()

When overridden in a derived class, creates and returns a DbCommand object associated with the current connection.

CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Dispose()

Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean)

Releases the unmanaged resources used by the DbConnection and optionally releases the managed resources.

Dispose(Boolean)

Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
DisposeAsync()

Asynchronously diposes the connection object.

EnlistTransaction(Transaction)

Enlists in the specified transaction.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetSchema()

Returns schema information for the data source of this DbConnection.

GetSchema(String)

Returns schema information for the data source of this DbConnection using the specified string for the schema name.

GetSchema(String, String[])

Returns schema information for the data source of this DbConnection using the specified string for the schema name and the specified string array for the restriction values.

GetSchemaAsync(CancellationToken)

This is an asynchronous version of GetSchema(). Providers should override with an appropriate implementation. The cancellationToken can optionally be honored. The default implementation invokes the synchronous GetSchema() call and returns a completed task. The default implementation will return a cancelled task if passed an already cancelled cancellationToken. Exceptions thrown by GetSchema() will be communicated via the returned Task Exception property.

GetSchemaAsync(String, CancellationToken)

This is the asynchronous version of GetSchema(String). Providers should override with an appropriate implementation. The cancellationToken can optionally be honored. The default implementation invokes the synchronous GetSchema(String) call and returns a completed task. The default implementation will return a cancelled task if passed an already cancelled cancellationToken. Exceptions thrown by GetSchema(String) will be communicated via the returned Task Exception property.

GetSchemaAsync(String, String[], CancellationToken)

This is the asynchronous version of GetSchema(String, String[]). Providers should override with an appropriate implementation. The cancellationToken can optionally be honored. The default implementation invokes the synchronous GetSchema(String, String[]) call and returns a completed task. The default implementation will return a cancelled task if passed an already cancelled cancellationToken. Exceptions thrown by GetSchema(String, String[]) will be communicated via the returned Task Exception property.

GetService(Type)

Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
OnStateChange(StateChangeEventArgs)

Raises the StateChange event.

Open()

When overridden in a derived class, opens a database connection with the settings specified by the ConnectionString.

OpenAsync()

An asynchronous version of Open(), which opens a database connection with the settings specified by the ConnectionString. This method invokes the virtual method OpenAsync(CancellationToken) with CancellationToken.None.

OpenAsync(CancellationToken)

This is the asynchronous version of Open(). Providers should override with an appropriate implementation. The cancellation token can optionally be honored.

The default implementation invokes the synchronous Open() call and returns a completed task. The default implementation will return a cancelled task if passed an already cancelled cancellationToken. Exceptions thrown by Open will be communicated via the returned Task Exception property.

Do not invoke other methods and properties of the DbConnection object until the returned Task is complete.

ToString()

Returns a string that represents the current object.

(Inherited from Object)
ToString()

Returns a String containing the name of the Component, if any. This method should not be overridden.

(Inherited from Component)

Events

Disposed

Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)
StateChange

Occurs when the state of the connection changes.

Explicit Interface Implementations

IDbConnection.BeginTransaction()

Begins a database transaction.

IDbConnection.BeginTransaction(IsolationLevel)

Begins a database transaction with the specified isolation level.

IDbConnection.CreateCommand()

Creates and returns a DbCommand object that is associated with the current connection.

Extension Methods

ConfigureAwait(IAsyncDisposable, Boolean)

Configures how awaits on the tasks returned from an async disposable are performed.

Applies to

See also