Represents a generic connection to a database. This interface is implemented by classes that provide database connectivity for ADO.NET.
The IDbConnection
interface is the base interface for all ADO.NET connection objects. It defines the core properties and methods required to establish and manage a connection to a database. Implementations of this interface provide specific connection logic for different database systems (e.g., SQL Server, Oracle, MySQL).
Key functionalities include:
public interface IDbConnection : IDisposable
public interface IDbConnection : IDisposable
{
// Properties
string ConnectionString { get; set; }
int ConnectionTimeout { get; }
string Database { get; }
ConnectionState State { get; }
// Methods
IDbTransaction BeginTransaction();
IDbTransaction BeginTransaction(IsolationLevel isolationLevel);
void ChangeDatabase(string databaseName);
void Close();
IDbCommand CreateCommand();
void Open();
}
Gets or sets the connection string used to open the connection.
Gets the time in seconds to wait while trying to establish a connection before the attempt times out.
Gets the name of the current database or the database to be used after a connection is opened.
Gets a value indicating the status of the connection.
Starts a database transaction.
Starts a database transaction with the specified isolation level.
Changes the current database for the connection with the specified name.
Closes the connection to the data source.
Creates and returns an IDbCommand object associated with the connection.
Opens a database connection with the properties and password specified by the ConnectionString property of the connected data source.
This interface inherits members from the System.IDisposable
interface.
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
System.Data.dll
System.Data
Windows 8.1, Windows 10, Windows Server 2012 R2, Windows Server 2016, Windows Server 2019, .NET Framework 1.1, .NET Framework 2.0, .NET Framework 3.0, .NET Framework 3.5, .NET Framework 4.0, .NET Framework 4.5, .NET Framework 4.6, .NET Framework 4.7, .NET Framework 4.8, .NET Core 1.0, .NET Core 1.1, .NET Core 2.0, .NET Core 2.1, .NET Core 2.2, .NET Standard 1.0, .NET Standard 1.1, .NET Standard 1.2, .NET Standard 1.3, .NET Standard 1.4, .NET Standard 1.5, .NET Standard 1.6, .NET Standard 2.0, .NET Standard 2.1, .NET 5, .NET 6, .NET 7, .NET 8