ADO.NET

ADO.NET, also known as System.Data, is the foundational library for database access in .NET. This is done via a set of interfaces and abstract classes, allowing for a consistent experience.

Of these, the most important are IDbConnection, IDbCommand, and IDataReader.

Supported Databases

All databases that offer OleDB or ODBC connectivity are automatically supported.

Most databases also implement their own ADO.NET provider. that implements the ADO.NET interfaces and abstract classes. This allows greater access to the specific database's capabilities than using the generic OleDB or ODBC drivers.

ADO.NET requires the writing of SQL, which is often database specific.

Warning!

Unless otherwise indicated, all examples of SQL are for SQL Server.

Libraries

ADO.NET is incorporated into .NET Framework. This includes the SQL Server, OleDB, and ODBC libraries.

For .NET Core, you'll need the System.Data.Common package.

Setup

No special setup is needed for ADO.NET beyond just a connection string.

/// <summary>
/// Opens a database connection.
/// </summary>
/// <remarks>Caller must dispose the connection.</remarks>
protected SqlConnection OpenConnection()
{
    var con = new SqlConnection(m_ConnectionString);
    con.Open();
    return con;
}

The exact class names vary by database.

/// <summary>
/// Opens a database connection.
/// </summary>
/// <remarks>Caller must dispose the connection.</remarks>
protected NpgsqlConnection OpenConnection()
{
    var con = new NpgsqlConnection(m_ConnectionString);
    con.Open();
    return con;
}

For information on creating connection strings, try The Connection Strings Reference.

Documentation and Tutorials

Individual ADO.NET providers may have their own documentation as well.

Bug Reporting

Most ADO.NET bugs should be reported to their respective provider maintainers.

For ADO.NET itself, issues should be logged in the dotnet/runtime repository.

Licensing

ADO.NET itself is offered under the The MIT License.

Individual ADO.NET providers may be licensed differently.