The Microsoft SQL Server Data-Tier Application Framework (DacFx) is a .NET library which provides application lifecycle services for database development and management for Microsoft SQL databases. DacFx supports various database deployment and management scenarios, including extracting / exporting a live database to a DAC package, deploying a DAC package to a new or existing database, and migrating from on-premises to Microsoft Azure. DacFx can target all supported versions of SQL Server, as well as Microsoft Azure SQL and SQL in Fabric. If you would like to use DacFx functionality from the command-line for creating and deploying .dacpac and .bacpac packages, please use the [SqlPackage](https://www.nuget.org/packages/Microsoft.SqlPackage) CLI as a dotnet tool or downloadable exe. Learn more about SqlPackage from http://aka.ms/sqlpackage.
$ dotnet add package Microsoft.SqlServer.DacFxThe Microsoft SQL Server Data-Tier Application Framework (DacFx) is a .NET library which provides application lifecycle services for database development and management for Microsoft SQL databases. DacFx supports various database deployment and management scenarios, including extracting / exporting a live database to a DAC package, deploying a DAC package to a new or existing database, and migrating from on-premises to Microsoft Azure. DacFx can target all supported versions of SQL Server, as well as Microsoft Azure SQL and SQL in Fabric.
📘 DacFx .NET API documentation
📗 SQL projects database DevOps documentation
If you would like to use DacFx functionality from the command-line for creating and deploying .dacpac and .bacpac packages, please use the SqlPackage CLI as a dotnet tool or downloadable exe. Learn more about SqlPackage from http://aka.ms/sqlpackage.
The following examples demonstrate some basic functionality of the DacFx API. For more detailed examples, please refer to the DacFx API documentation.
using Microsoft.SqlServer.Dac;
string dacpacPath = "path\\to\\your.dacpac";
string connectionString = "your-database-connection-string";
DacServices dacServices = new DacServices(connectionString);
DacPackage dacPackage = DacPackage.Load(dacpacPath);
dacServices.Deploy(dacPackage, "TargetDatabaseName", upgradeExisting: true);
using Microsoft.SqlServer.Dac;
string connectionString = "your-database-connection-string";
string dacpacOutputPath = "path\\to\\output.dacpac";
DacServices dacServices = new DacServices(connectionString);
DacExtractOptions extractOptions = new DacExtractOptions();
dacServices.Extract(dacpacOutputPath, "SourceDatabaseName", "SourceDatabaseName", extractOptions);
using Microsoft.SqlServer.Dac;
string connectionString = "your-database-connection-string";
string sqlOutputDirectory = "path\\to\\output\\directory";
DacServices dacServices = new DacServices(connectionString);
DacExtractOptions extractOptions = new DacExtractOptions
{
ExtractTarget = DacExtractTarget.SchemaObjectType
};
dacServices.Extract(sqlOutputDirectory, "SourceDatabaseName", "SourceDatabaseName", extractOptions);
| Component | Links | Summary |
|---|---|---|
| SqlPackage | 📦 Tool<br/>📗 Docs | Microsoft.SqlPackage is a cross-platform command-line utility for creating and deploying .dacpac and .bacpac packages. SqlPackage can be installed as a dotnet tool. |
| DacpacVerify | 📦 Tool | Microsoft.DacpacVerify is a cross-platform command-line utility for checking that two .dacpac packages match, including pre/post-deployment scripts and SQLCMD variables. |
| Dacpacs.(Master,Msdb) | 📦 Master<br/>📦 Msdb | Microsoft.SqlServer.Dacpacs.Master and Microsoft.SqlServer.Dacpacs.Msdb is a set of NuGet packages containing .dacpac files for Microsoft SQL Server system databases (master, msdb) with versions across SQL Server 2008 (100) through SQL Server 2022 (160). |
| Dacpacs.Azure.Master | 📦 NuGet | Microsoft.SqlServer.Dacpacs.Azure.Master is a NuGet package containing a .dacpac file for the Azure SQL Database master database. |
| Dacpacs.DbFabric | 📦 NuGet | Microsoft.SqlServer.Dacpacs.DbFabric is a NuGet package containing a .dacpac file for the SQL database in Fabric system objects. |
| Dacpacs.Synapse.Master | 📦 NuGet | Microsoft.SqlServer.Dacpacs.Synapse.Master is a NuGet package containing a .dacpac file for the Azure Synapse Analytics master database. |
| Dacpacs.SynapseServerless.Master | 📦 NuGet | Microsoft.SqlServer.Dacpacs.SynapseServerless.Master is a NuGet package containing a .dacpac file for the Azure Synapse Analytics serverless SQL pools master database. |
| ScriptDom | 📦 NuGet<br/>🛠️ Code<br/>📘 API Docs | Microsoft.SqlServer.TransactSql.ScriptDom is a NuGet package containing the Transact-SQL parser ScriptDOM. The source code is licensed MIT. |
| Microsoft.Build.Sql | 📦 NuGet<br/>📗 Docs<br/>🛠️ Code | Microsoft.Build.Sql is a .NET project SDK for SQL projects, compiling T-SQL code to a data-tier application package (dacpac). |
| Project Templates | 📦 NuGet<br/>🛠️ Code | Microsoft.Build.Sql.Templates is a set of .NET project templates for SQL projects. |
Open issues at DacFx GitHub
We would like to inform you about an important change in DacFx NuGet that may impact your applications. We have updated the public key in the DLLs included in this package. This change is crucial for enhancing the security and integrity of our assembly but may cause breaking changes in your C# applications.
To mitigate the impact of this change, we recommend the following steps: