Represents an open connection to a data source, and is implemented by .NET Framework data providers that access relational databases.
Assembly: System.Data (in System.Data.dll)
Thetype exposes the following members.
|ConnectionString||Gets or sets the string used to open a database.|
|ConnectionTimeout||Gets the time to wait while trying to establish a connection before terminating the attempt and generating an error.|
|Database||Gets the name of the current database or the database to be used after a connection is opened.|
|State||Gets the current state of the connection.|
|BeginTransaction()||Begins a database transaction.|
|BeginTransaction(IsolationLevel)||Begins a database transaction with the specified IsolationLevel value.|
|ChangeDatabase||Changes the current database for an open Connection object.|
|Close||Closes the connection to the database.|
|CreateCommand||Creates and returns a Command object associated with the connection.|
|Dispose||Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. (Inherited from IDisposable.)|
|Open||Opens a database connection with the settings specified by the ConnectionString property of the provider-specific Connection object.|
The interface enables an inheriting class to implement a Connection class, which represents a unique session with a data source (for example, a network connection to a server). For more information about Connection classes, see Connecting to a Data Source [from BPUEDev11].
An application does not create an instance of the interface directly, but creates an instance of a class that inherits .
Classes that inherit must implement all inherited members, and typically define additional members to add provider-specific functionality. For example, the interface defines the ConnectionTimeout property. In turn, the SqlConnection class inherits this property, and also defines the PacketSize property.Notes to Implementers
To promote consistency among .NET Framework data providers, name the inheriting class in the form PrvClassname where Prv is the uniform prefix given to all classes in a specific .NET Framework data provider namespace. For example, Sql is the prefix of the SqlConnection class in the System.Data.SqlClient namespace.
When you inherit from the interface, you should implement the following constructors:
Initializes a new instance of the PrvConnection class.
Initializes a new instance of the PrvConnection class when given a string containing the connection string.
The following example creates instances of the derived classes, SqlCommand and SqlConnection. The SqlConnection is opened and set as the Connection for the SqlCommand. The example then calls ExecuteNonQuery, and closes the connection. To accomplish this, the ExecuteNonQuery is passed a connection string and a query string that is a Transact-SQL INSERT statement.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.