Microsoft.Data.SqlClient
7.0.0
Prefix Reserved
Requires NuGet 2.12 or higher.
dotnet add package Microsoft.Data.SqlClient --version 7.0.0
NuGet\Install-Package Microsoft.Data.SqlClient -Version 7.0.0
<PackageReference Include="Microsoft.Data.SqlClient" Version="7.0.0" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="7.0.0" />
<PackageReference Include="Microsoft.Data.SqlClient" />
paket add Microsoft.Data.SqlClient --version 7.0.0
#r "nuget: Microsoft.Data.SqlClient, 7.0.0"
#:package Microsoft.Data.SqlClient@7.0.0
#addin nuget:?package=Microsoft.Data.SqlClient&version=7.0.0
#tool nuget:?package=Microsoft.Data.SqlClient&version=7.0.0
Microsoft.Data.SqlClient
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:
- Native SNI: Windows-only, provided via Microsoft.Data.SqlClient.SNI (.NET Framework) or Microsoft.Data.SqlClient.SNI.runtime (.NET on Windows)
- Managed SNI: Cross-platform managed implementation, used by default on Unix platforms
Documentation
- Microsoft.Data.SqlClient Documentation
- Connection String Syntax
- Connection Pooling
- Always Encrypted
- Entra ID Authentication
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:
- Change namespace from
System.Data.SqlClienttoMicrosoft.Data.SqlClient - Update package reference to
Microsoft.Data.SqlClient - Review connection string defaults (e.g.,
Encrypt=Mandatoryis now the default)
License
This package is licensed under the MIT License.
Related Packages
- Microsoft.Data.SqlClient.Extensions.Azure - Entra ID authentication provider with Azure.Identity integration
- Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider - Azure Key Vault integration for Always Encrypted
- Microsoft.SqlServer.Server - SQL CLR UDT support
- Microsoft.Data.SqlClient.SNI - Native SNI for .NET Framework
- Microsoft.Data.SqlClient.SNI.runtime - Native SNI runtime for .NET on Windows
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- Microsoft.Bcl.Cryptography (>= 8.0.0)
- Microsoft.Data.SqlClient.Extensions.Abstractions (>= 1.0.0)
- Microsoft.Data.SqlClient.Internal.Logging (>= 1.0.0)
- Microsoft.Data.SqlClient.SNI (>= 6.0.2)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.16.0)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 8.16.0)
- System.Buffers (>= 4.6.1)
- System.Diagnostics.DiagnosticSource (>= 10.0.3)
- System.Memory (>= 4.6.3)
- System.Runtime.InteropServices.RuntimeInformation (>= 4.3.0)
- System.Security.Cryptography.Pkcs (>= 8.0.1)
- System.Text.Json (>= 10.0.3)
- System.Threading.Channels (>= 10.0.3)
- System.ValueTuple (>= 4.6.2)
-
.NETStandard 2.0
- Microsoft.Bcl.Cryptography (>= 8.0.0)
- Microsoft.Data.SqlClient.Extensions.Abstractions (>= 1.0.0)
- Microsoft.Data.SqlClient.Internal.Logging (>= 1.0.0)
- Microsoft.Data.SqlClient.SNI.runtime (>= 6.0.2)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.16.0)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 8.16.0)
- Microsoft.SqlServer.Server (>= 1.0.0)
- System.Configuration.ConfigurationManager (>= 8.0.1)
- System.Security.Cryptography.Pkcs (>= 8.0.1)
- System.Text.Json (>= 10.0.3)
- System.Threading.Channels (>= 10.0.3)
-
net8.0
- Microsoft.Bcl.Cryptography (>= 8.0.0)
- Microsoft.Data.SqlClient.Extensions.Abstractions (>= 1.0.0)
- Microsoft.Data.SqlClient.Internal.Logging (>= 1.0.0)
- Microsoft.Data.SqlClient.SNI.runtime (>= 6.0.2)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.16.0)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 8.16.0)
- Microsoft.SqlServer.Server (>= 1.0.0)
- System.Configuration.ConfigurationManager (>= 8.0.1)
- System.Security.Cryptography.Pkcs (>= 8.0.1)
-
net9.0
- Microsoft.Bcl.Cryptography (>= 9.0.13)
- Microsoft.Data.SqlClient.Extensions.Abstractions (>= 1.0.0)
- Microsoft.Data.SqlClient.Internal.Logging (>= 1.0.0)
- Microsoft.Data.SqlClient.SNI.runtime (>= 6.0.2)
- Microsoft.Extensions.Caching.Memory (>= 9.0.13)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.16.0)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 8.16.0)
- Microsoft.SqlServer.Server (>= 1.0.0)
- System.Configuration.ConfigurationManager (>= 9.0.13)
- System.Security.Cryptography.Pkcs (>= 9.0.13)
NuGet packages (3.0K)
Showing the top 5 NuGet packages that depend on Microsoft.Data.SqlClient:
| Package | Downloads |
|---|---|
|
Microsoft.EntityFrameworkCore.SqlServer
Microsoft SQL Server database provider for Entity Framework Core. |
|
|
AspNetCore.HealthChecks.SqlServer
HealthChecks.SqlServer is the health check package for SqlServer. |
|
|
Microsoft.Extensions.Caching.SqlServer
Distributed cache implementation of Microsoft.Extensions.Caching.Distributed.IDistributedCache using Microsoft SQL Server. This package was built from the source code at https://github.com/dotnet/dotnet/tree/17d11de66cf75b962995c81dd1235fae9aa5ece0 |
|
|
Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite
NetTopologySuite support for the Microsoft SQL Server database provider for Entity Framework Core. |
|
|
Serilog.Sinks.MSSqlServer
A Serilog sink that writes events to Microsoft SQL Server and Azure SQL |
GitHub repositories (252)
Showing the top 20 popular GitHub repositories that depend on Microsoft.Data.SqlClient:
| Repository | Stars |
|---|---|
|
microsoft/semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
|
|
|
bitwarden/server
Bitwarden infrastructure/backend (API, database, Docker, etc).
|
|
|
DapperLib/Dapper
Dapper - a simple object mapper for .Net
|
|
|
dotnet/efcore
EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
|
|
|
Sonarr/Sonarr
Smart PVR for newsgroup and bittorrent users.
|
|
|
Radarr/Radarr
Movie organizer/manager for usenet and torrent users.
|
|
|
mRemoteNG/mRemoteNG
mRemoteNG is the next generation of mRemote, open source, tabbed, multi-protocol, remote connections manager.
|
|
|
HangfireIO/Hangfire
An easy way to perform background job processing in .NET and .NET Core applications. No Windows Service or separate process required
|
|
|
nopSolutions/nopCommerce
ASP.NET Core eCommerce software. nopCommerce is a free and open-source shopping cart.
|
|
|
TechnitiumSoftware/DnsServer
Technitium DNS Server
|
|
|
MassTransit/MassTransit
Distributed Application Framework for .NET
|
|
|
dotnetcore/CAP
Distributed transaction solution in micro-service base on eventually consistency, also an eventbus with Outbox pattern
|
|
|
quartznet/quartznet
Quartz Enterprise Scheduler .NET
|
|
|
Prowlarr/Prowlarr
Prowlarr is an indexer manager/proxy built on the popular *arr .net/reactjs base stack to integrate with your various PVR apps, supporting management of both Torrent Trackers and Usenet Indexers.
|
|
|
Azure/azure-sdk-for-net
This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
|
|
|
danielgerlag/workflow-core
Lightweight workflow engine for .NET Standard
|
|
|
DotNetNext/SqlSugar
.Net aot ORM SqlServer ORM Mongodb ORM MySql 瀚高 Postgresql ORM DB2 Hana 高斯 Duckdb C# VB.NET Sqlite ORM Oracle ORM Mysql Orm 虚谷数据库 达梦 ORM 人大金仓 ORM 神通ORM C# ORM , C# ORM .NET ORM NET9 ORM .NET8 ORM ClickHouse ORM QuestDb ,TDengine ORM,OceanBase ORM,GaussDB ORM,Tidb ORM Object/Relational Mapping
|
|
|
ServiceStack/ServiceStack
Thoughtfully architected, obscenely fast, thoroughly enjoyable web services for all
|
|
|
umbraco/Umbraco-CMS
Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
|
|
|
Lidarr/Lidarr
Looks and smells like Sonarr but made for music.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 7.0.0 | 563 | 3/17/2026 |
| 7.0.0-preview4.26064.3 | 6,303 | 3/5/2026 |
| 7.0.0-preview3.25342.7 | 98,177 | 12/8/2025 |
| 7.0.0-preview2.25289.6 | 73,308 | 10/16/2025 |
| 7.0.0-preview1.25257.1 | 41,973 | 9/14/2025 |
| 6.1.4 | 5,199,611 | 1/15/2026 |
| 6.1.3 | 7,411,941 | 11/12/2025 |
| 6.1.2 | 6,945,676 | 10/8/2025 |
| 6.1.1 | 18,092,491 | 8/14/2025 |
| 6.1.0-preview2.25178.5 | 84,827 | 6/27/2025 |
| 6.1.0-preview1.25120.4 | 62,682 | 4/30/2025 |
| 6.0.5 | 30,323 | 1/16/2026 |
| 6.0.4 | 63,681 | 11/15/2025 |
| 6.0.3 | 76,045 | 10/8/2025 |
| 6.0.2 | 19,711,378 | 4/25/2025 |
| 5.2.3 | 6,269,859 | 4/29/2025 |
| 5.1.9 | 40,589 | 1/13/2026 |
| 5.1.8 | 55,530 | 11/14/2025 |