Edit

Install, update, and deploy Microsoft.Data.SqlClient

Microsoft.Data.SqlClient is the supported .NET data provider for SQL Server, Azure SQL Database, Azure SQL Managed Instance, Azure Synapse Analytics, SQL database in Microsoft Fabric, and Warehouse in Microsoft Fabric. The driver ships as NuGet packages independently of the .NET runtime.

Choose a release

Use a supported General Availability (GA) release for production applications. The latest GA release is Microsoft.Data.SqlClient 8.0.0. Version 8.0 supports .NET 10 and later versions, and .NET Framework 4.6.2 and later versions. For applications that target .NET 8 or .NET 9, the latest compatible release is 7.1.2. The 6.1 Long Term Support (LTS) line also supports those versions.

Release line Latest version Support level Choose it when
8.0 8.0.0 Standard Term Support (STS) You target .NET 10 or .NET Framework and need current driver features.
7.1 7.1.2 Standard Term Support (STS) You target .NET 8 or .NET 9, or you need time to prepare for the 8.0 changes before support ends on February 26, 2027.
7.0 7.0.4 Standard Term Support (STS) You need servicing fixes while you prepare to upgrade before support ends on December 17, 2026.
6.1 6.1.8 Long Term Support (LTS) You prefer a longer support period and don't need features introduced in 7.x.

For current patch versions, support dates, target frameworks, and database compatibility, see SqlClient driver support lifecycle.

Install the core package

Run the following command from the directory that contains your project file:

dotnet add package Microsoft.Data.SqlClient

The command selects the latest stable version that NuGet considers compatible with the project. Because the package contains a .NET Standard 2.0 asset, NuGet selects version 8.0.0 for a project that targets .NET 8 or .NET 9, and the application fails at run time with PlatformNotSupportedException. For those projects, pin version 7.1.2. To pin a version for repeatable builds, specify the version:

dotnet add package Microsoft.Data.SqlClient --version <version>

The command adds a package reference to your project file. For version 8.0.0, the project file contains this line:

<PackageReference Include="Microsoft.Data.SqlClient" Version="8.0.0" />

If you also add Microsoft.Data.SqlClient.Extensions.Azure, its PackageReference uses the same version.

Restore dependencies and build the project:

dotnet restore
dotnet build

If restore or build of version 7.1.2 or an earlier version reports a warning about a package with a known vulnerability, such as NU1902 or NU1903, follow the steps in Actions when packages with known vulnerabilities are reported.

Import the driver namespace in C#:

using Microsoft.Data.SqlClient;

For new applications, don't reference the older System.Data.SqlClient package or namespace. To update an existing application, see Migrate from System.Data.SqlClient to Microsoft.Data.SqlClient.

Install with Visual Studio

  1. In Solution Explorer, right-click the project, and select Manage NuGet Packages.
  2. On the Browse tab, search for Microsoft.Data.SqlClient.
  3. Select the package owned by Microsoft.
  4. Select a supported stable version, and then select Install.

For more information, see Install and manage packages in Visual Studio using the NuGet Package Manager.

Add optional packages

Install optional packages only when your application uses the related feature.

Package Add it when
Microsoft.Data.SqlClient.Extensions.Azure Microsoft.Data.SqlClient 7.0 or later uses a driver-provided Microsoft Entra authentication mode, such as Active Directory Default, Active Directory Interactive, or Active Directory Managed Identity.
Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider Always Encrypted stores column master keys in Azure Key Vault.

For Microsoft Entra authentication with SqlClient 7.0 or later, run:

dotnet add package Microsoft.Data.SqlClient.Extensions.Azure --version <same-version-as-Microsoft.Data.SqlClient>

The 7.0 core package no longer includes Azure Identity dependencies. Starting with version 7.0.2, the core driver and companion packages use aligned versions. Reference the same version of Microsoft.Data.SqlClient and Microsoft.Data.SqlClient.Extensions.Azure. Applications that don't use driver-provided Microsoft Entra authentication don't need the Azure extension package. For authentication setup, see Microsoft Entra authentication with Microsoft.Data.SqlClient.

Update the driver

  1. Before you update, check these items:

    • Read What's new in Microsoft.Data.SqlClient and the upstream release notes for each version crossed by the update.

    • List the application's direct and transitive package references:

      dotnet list package --include-transitive
      
    • Note every companion package that the application references directly, such as Microsoft.Data.SqlClient.Extensions.Azure or Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider.

  2. Update the package reference.

    dotnet add package Microsoft.Data.SqlClient --version <version>
    
  3. For version 7.0.2 and later, update each directly referenced companion package to the same version.

  4. Restore, build, and run the application's tests.

  5. Test connection establishment, authentication, certificate validation, connection pooling, data type conversions, transactions, and retry behavior against each supported database target.

Major and patch releases can require application changes. For example, version 4.0 enabled encryption by default, version 5.0 changed SqlConnectionStringBuilder.Encrypt from bool to SqlConnectionEncryptOption, version 7.0 moved driver-provided Microsoft Entra authentication into a separate package, and version 8.0 requires .NET 10 for modern .NET applications and turns on MultiSubnetFailover by default. For the 8.0 changes, see What's new in Microsoft.Data.SqlClient.

Starting with version 7.0.2, the assembly versions of Microsoft.Data.SqlClient.Extensions.Azure, Microsoft.Data.SqlClient.Extensions.Abstractions, and Microsoft.Data.SqlClient.Internal.Logging changed from 1.0.0.0 to 7.0.0.0. .NET Framework applications must rebuild against the aligned packages or add binding redirects. Applications on current .NET aren't affected by this assembly identity change.

Version 8.0 changes the assembly version of the driver and its companion packages from 7.0.0.0 to 8.0.0.0. .NET Framework applications that upgrade from 7.x must rebuild or update their binding redirects. A build that references family packages with different versions emits warning SQLCLIENT001.

Understand target frameworks

Release line .NET .NET Framework
8.0 .NET 10 and later versions on supported Windows, Linux, and macOS versions 4.6.2 and later versions on Windows
7.1, 7.0, and 6.1 .NET 8 and later versions on supported Windows, Linux, and macOS versions 4.6.2 and later versions on Windows

The NuGet package also contains a .NET Standard 2.0 asset for libraries. An executable application must target a supported .NET or .NET Framework runtime. A library's .NET Standard target doesn't make every consuming runtime supported. On .NET 8 or .NET 9, an application that references 8.0 builds without errors and then throws PlatformNotSupportedException at run time.

The package restores its managed and native dependencies through NuGet. Don't copy individual driver assemblies or native SQL Network Interface (SNI) libraries between applications.

.NET Framework projects

The samples in these articles target .NET. For new development, use .NET instead of .NET Framework. For more information, see Overview of .NET Framework.

Projects that target .NET Framework use C# 7.3 by default, so a sample written for .NET doesn't compile there without changes. Quickstart: Connect and query with Microsoft.Data.SqlClient has a .NET Framework tab with a C# 7.3 version of its sample.

Prepare for deployment

  1. Publish for the same operating system and architecture used in production. For a framework-dependent deployment:

    dotnet publish --configuration Release
    

    For a runtime-specific deployment:

    dotnet publish --configuration Release --runtime <runtime-identifier>
    
  2. Deploy the complete publish output. Don't select only Microsoft.Data.SqlClient.dll.

  3. Confirm that the target has the required .NET runtime unless you publish a self-contained application.

  4. Test the published output on the target operating system and architecture.

  5. Test every authentication mode used in production. Integrated authentication, Kerberos, certificates, managed identity, and Azure Key Vault access depend on the deployment environment.

  6. Scan the resolved dependency graph for known vulnerabilities and update supported package lines when fixes are available.

Globalization-invariant mode isn't supported. For current platform qualifications, see Supported operating systems.

Offline package installation

Download the package and its dependencies from NuGet.org, copy them to an internal package source, and restore from that source. For repeatable offline builds, pin package versions and preserve the complete dependency set.