Microsoft.Data.SqlClient 7.1.0-preview3.26238.4

Microsoft.Data.SqlClient

NuGet NuGet Downloads

Description

Microsoft.Data.SqlClient is the official .NET data provider for Microsoft SQL Server and Azure SQL databases. It provides access to SQL Server and encapsulates database-specific protocols, including Tabular Data Stream (TDS).

This library grew from a union of the two System.Data.SqlClient components which live independently in .NET and .NET Framework. Going forward, support for new SQL Server and Azure SQL features will only be implemented in Microsoft.Data.SqlClient.

Supportability

This package supports:

  • .NET Framework 4.6.2+
  • .NET 8.0+

Installation

Install the package via NuGet:

dotnet add package Microsoft.Data.SqlClient

Or via the Package Manager Console:

Install-Package Microsoft.Data.SqlClient

Getting Started

Basic Connection

using Microsoft.Data.SqlClient;

var connectionString = "Server=myserver;Database=mydb;Integrated Security=true;";

using var connection = new SqlConnection(connectionString);
await connection.OpenAsync();

Console.WriteLine("Connected successfully!");

Connecting to Azure

Starting with v7.0, to use Entra ID authentication modes (such as Active Directory Default, Active Directory Managed Identity, Active Directory Interactive, etc.) via connection string keywords, install the Microsoft.Data.SqlClient.Extensions.Azure extension package via NuGet:

dotnet add package Microsoft.Data.SqlClient.Extensions.Azure

Or via the Package Manager Console:

Install-Package Microsoft.Data.SqlClient.Extensions.Azure

This package provides the ActiveDirectoryAuthenticationProvider, which integrates with Azure.Identity to handle token acquisition, caching, and credential management.

With this package reference, you can continue to use Entra ID authentication modes directly in your connection string:

// Active Directory Default — uses DefaultAzureCredential (Managed Identity, Azure CLI, Visual Studio, etc.)
var connectionString = "Server=myserver.database.windows.net;Database=mydb;Authentication=Active Directory Default;";

using var connection = new SqlConnection(connectionString);
await connection.OpenAsync();

Execute a Query

using Microsoft.Data.SqlClient;

var connectionString = "Server=myserver;Database=mydb;Integrated Security=true;";

using var connection = new SqlConnection(connectionString);
await connection.OpenAsync();

using var command = new SqlCommand("SELECT Id, Name FROM Customers", connection);
using var reader = await command.ExecuteReaderAsync();

while (await reader.ReadAsync())
{
    Console.WriteLine($"Id: {reader.GetInt32(0)}, Name: {reader.GetString(1)}");
}

Parameterized Query

using Microsoft.Data.SqlClient;

var connectionString = "Server=myserver;Database=mydb;Integrated Security=true;";

using var connection = new SqlConnection(connectionString);
await connection.OpenAsync();

using var command = new SqlCommand("SELECT * FROM Customers WHERE Id = @id", connection);
command.Parameters.AddWithValue("@id", customerId);

using var reader = await command.ExecuteReaderAsync();
// Process results...

Using Transactions

using Microsoft.Data.SqlClient;

using var connection = new SqlConnection(connectionString);
await connection.OpenAsync();

using var transaction = connection.BeginTransaction();

try
{
    using var command = new SqlCommand("INSERT INTO Orders (CustomerId, Total) VALUES (@customerId, @total)", connection, transaction);
    command.Parameters.AddWithValue("@customerId", customerId);
    command.Parameters.AddWithValue("@total", orderTotal);
    
    await command.ExecuteNonQueryAsync();
    await transaction.CommitAsync();
}
catch
{
    await transaction.RollbackAsync();
    throw;
}

Key Features

Feature Description
Cross-Platform Runs on Windows, Linux, and macOS
Entra ID Authentication Multiple Entra ID authentication modes
Always Encrypted Client-side encryption for sensitive data
Connection Pooling Efficient connection management
TLS 1.3 Support Enhanced security with strict encryption mode
MARS Multiple Active Result Sets on a single connection
Async Programming Full async/await support
SqlBatch Batch multiple commands for improved performance
JSON/Vector Support Native support for JSON and Vector data types (SQL Server 2025+)

Commonly Used Types

Microsoft.Data.SqlClient.SqlConnection
Microsoft.Data.SqlClient.SqlCommand
Microsoft.Data.SqlClient.SqlDataReader
Microsoft.Data.SqlClient.SqlParameter
Microsoft.Data.SqlClient.SqlTransaction
Microsoft.Data.SqlClient.SqlException
Microsoft.Data.SqlClient.SqlParameterCollection
Microsoft.Data.SqlClient.SqlClientFactory
Microsoft.Data.SqlClient.SqlBulkCopy
Microsoft.Data.SqlClient.SqlConnectionStringBuilder

Authentication Methods

Method Connection String
SQL Server Authentication User ID=user;Password=pass;
Windows Authentication Integrated Security=true;
Entra ID Password (deprecated) Authentication=Active Directory Password;User ID=user;Password=pass;
Entra ID Integrated Authentication=Active Directory Integrated;
Entra ID Interactive Authentication=Active Directory Interactive;
Entra ID Managed Identity Authentication=Active Directory Managed Identity;
Entra ID Service Principal Authentication=Active Directory Service Principal;User ID=clientId;Password=clientSecret;
Entra ID Default Authentication=Active Directory Default;
Entra ID Workload Identity Authentication=Active Directory Workload Identity;User ID=clientId;

Note: To use Entra ID authentication modes (such as Active Directory Default, Active Directory Managed Identity, Active Directory Interactive, etc.) via connection string keywords, install the Microsoft.Data.SqlClient.Extensions.Azure extension package.

Encryption Modes

Mode Description
Encrypt=Optional Encryption is used if available
Encrypt=Mandatory Encryption is required (default)
Encrypt=Strict TDS 8.0 with TLS 1.3 support

SNI (SQL Server Network Interface)

Two implementations are available:

Documentation

Release Notes

Release notes are available at: https://go.microsoft.com/fwlink/?linkid=2090501

Migrating from System.Data.SqlClient

If you're migrating from System.Data.SqlClient, see the porting cheat sheet for guidance.

Key changes:

  1. Change namespace from System.Data.SqlClient to Microsoft.Data.SqlClient
  2. Update package reference to Microsoft.Data.SqlClient
  3. Review connection string defaults (e.g., Encrypt=Mandatory is now the default)

License

This package is licensed under the MIT License.

Showing the top 20 packages that depend on Microsoft.Data.SqlClient.

Packages Downloads
FluentMigrator.Runner.SqlServer
FluentMigrator is a database migration framework for .NET written in C#. The basic idea is that you can create migrations which are simply classes that derive from the Migration base class and have a Migration attribute with a unique version number attached to them. Upon executing FluentMigrator, you tell it which version to migrate to and it will run all necessary migrations in order to bring your database up to that version. In addition to forward migration support, FluentMigrator also supports different ways to execute the migrations along with selective migrations called profiles and executing arbitrary SQL.
163
Microsoft.EntityFrameworkCore.SqlServer
Microsoft SQL Server database provider for Entity Framework Core.
163
Microsoft.EntityFrameworkCore.SqlServer
Microsoft SQL Server database provider for Entity Framework Core.
164
Microsoft.EntityFrameworkCore.SqlServer
Microsoft SQL Server database provider for Entity Framework Core.
165
Microsoft.EntityFrameworkCore.SqlServer
Microsoft SQL Server database provider for Entity Framework Core.
166
Microsoft.EntityFrameworkCore.SqlServer
Microsoft SQL Server database provider for Entity Framework Core.
167
Microsoft.EntityFrameworkCore.SqlServer
Microsoft SQL Server database provider for Entity Framework Core.
170
Microsoft.EntityFrameworkCore.SqlServer
Microsoft SQL Server database provider for Entity Framework Core.
171
Microsoft.EntityFrameworkCore.SqlServer
Microsoft SQL Server database provider for Entity Framework Core.
175
Microsoft.EntityFrameworkCore.SqlServer
Microsoft SQL Server database provider for Entity Framework Core.
252
Microsoft.EntityFrameworkCore.SqlServer
Microsoft SQL Server database provider for Entity Framework Core.
282
Microsoft.EntityFrameworkCore.SqlServer
Microsoft SQL Server database provider for Entity Framework Core.
305
Microsoft.Extensions.Caching.SqlServer
Distributed cache implementation of Microsoft.Extensions.Caching.Distributed.IDistributedCache using Microsoft SQL Server.
163
Microsoft.Extensions.Caching.SqlServer
Distributed cache implementation of Microsoft.Extensions.Caching.Distributed.IDistributedCache using Microsoft SQL Server.
167

https://go.microsoft.com/fwlink/?linkid=2090501

.NET Framework 4.6.2

.NET 9.0

.NET Standard 2.0

.NET 8.0

Version Downloads Last updated
7.1.0-preview3.26238.4 1 08/27/2026
7.1.0-preview2.26190.5 33 07/10/2026
7.1.0-preview2.26190.3 28 07/10/2026
7.1.0-preview1.26124.5 54 05/05/2026
7.0.2 32 06/26/2026
7.0.1 50 04/24/2026
7.0.0 62 03/17/2026
7.0.0-preview4.26064.3 48 03/06/2026
7.0.0-preview3.25342.7 81 12/09/2025
7.0.0-preview2.25289.6 84 10/17/2025
7.0.0-preview1.25257.1 107 09/15/2025
6.1.6 25 06/26/2026
6.1.5 45 04/28/2026
6.1.4 55 01/16/2026
6.1.3 117 11/13/2025
6.1.2 100 10/08/2025
6.1.1 115 08/15/2025
6.1.0 114 07/26/2025
6.1.0-preview2.25178.5 134 06/30/2025
6.1.0-preview1.25120.4 134 05/01/2025
6.0.5 70 01/16/2026
6.0.4 79 11/16/2025
6.0.3 100 10/08/2025
6.0.2 113 04/25/2025
6.0.1 136 03/30/2025
6.0.0-preview3.24332.3 120 12/02/2024
6.0.0-preview2.24304.8 129 11/14/2024
6.0.0-preview1.24240.8 138 09/19/2024
5.2.3 131 04/30/2025
5.2.2 118 09/01/2024
5.2.1 180 07/22/2024
5.2.0 184 07/22/2024
5.2.0-preview5.24024.3 156 07/22/2024
5.2.0-preview4.23342.2 198 07/22/2024
5.2.0-preview3.23201.1 161 07/22/2024
5.2.0-preview2.23159.1 159 07/22/2024
5.2.0-preview1.23109.1 147 07/22/2024
5.1.9 57 01/13/2026
5.1.8 94 11/15/2025
5.1.7 113 04/25/2025
5.1.6 164 09/01/2024
5.1.5 175 07/22/2024
5.1.4 170 07/22/2024
5.1.3 156 07/22/2024
5.1.2 141 07/22/2024
5.1.1 157 07/22/2024
5.1.0 156 07/17/2024
5.1.0-preview2.22314.2 157 07/22/2024
5.1.0-preview1.22279.3 158 07/22/2024
5.0.2 151 07/22/2024
5.0.1 163 02/04/2024
5.0.0 164 07/22/2024
5.0.0-preview3.22168.1 153 07/22/2024
5.0.0-preview2.22096.2 160 07/22/2024
5.0.0-preview1.22069.1 150 07/22/2024
4.1.1 149 07/22/2024
4.1.0 180 07/22/2024
4.0.6 145 08/22/2024
4.0.5 160 07/22/2024
4.0.4 135 07/22/2024
4.0.3 159 07/22/2024
4.0.2 143 07/22/2024
4.0.1 172 07/22/2024
4.0.0 140 06/24/2024
4.0.0-preview3.21293.2 154 07/22/2024
4.0.0-preview2.21264.2 159 07/22/2024
4.0.0-preview1.21237.2 133 07/22/2024
3.1.7 152 08/22/2024
3.1.6 116 09/21/2024
3.1.5 148 07/22/2024
3.1.4 162 07/22/2024
3.1.3 162 07/22/2024
3.1.2 140 07/22/2024
3.1.1 158 07/22/2024
3.1.0 147 07/22/2024
3.0.1 148 07/22/2024
3.0.0 142 07/22/2024
3.0.0-preview3.21140.5 151 07/22/2024
3.0.0-preview2.21106.5 145 07/22/2024
3.0.0-preview1.21075.2 125 07/22/2024
2.1.7 160 07/22/2024
2.1.6 159 07/22/2024
2.1.5 173 07/22/2024
2.1.4 183 02/04/2024
2.1.3 161 07/22/2024
2.1.2 157 07/22/2024
2.1.1 142 07/22/2024
2.1.0 152 07/22/2024
2.1.0-preview2.20297.7 164 07/22/2024
2.1.0-preview1.20235.1 172 07/22/2024
2.0.1 161 07/22/2024
2.0.0 171 07/22/2024
2.0.0-preview4.20142.4 171 07/22/2024
2.0.0-preview3.20122.2 150 07/22/2024
2.0.0-preview2.20084.1 142 07/22/2024
2.0.0-preview1.20021.1 141 07/21/2024
1.1.4 158 07/22/2024
1.1.3 165 07/22/2024
1.1.2 158 07/22/2024
1.1.1 150 07/22/2024
1.1.0 166 07/22/2024
1.1.0-preview2.19309.1 137 07/22/2024
1.1.0-preview1.19275.1 158 07/22/2024
1.0.19269.1 168 07/22/2024
1.0.19249.1 163 07/22/2024
1.0.19239.1 147 07/22/2024
1.0.19221.1-Preview 153 07/22/2024
1.0.19189.1-Preview 148 07/22/2024
1.0.19128.1-Preview 150 07/22/2024
1.0.19123.2-Preview 145 07/22/2024