4

I'm trying to migrate my app from net 4.6.1 to netcore2.0 and some problems with Microsoft.SqlServer.Dac have been occurred. I'm deploying the database from a .dacpac file using DacServices (Microsoft.SqlServer.Dac 1.0.1), but this package supports only net 4.6.1. How can I deploy .dacpac file from netcore application? Thanks for answers!

3 Answers 3

8

The .NET Core support for DacFx is planned, but not here yet and you can't do it this way in .NET Core. Now if add a NuGet package Microsoft.SqlServer.DacFx.x64 restore will print you:

Package 'Microsoft.SqlServer.DacFx.x64 140.3881.1' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'

For a while, you can use the command line utility SqlPackage.exe

SqlPackage.exe 
  /Action:Publish 
  /SourceFile:C:/file.dacpac 
  /TargetConnectionString:[Connection string]

And you can run it programmatically:

var process = new System.Diagnostics.Process();
var startInfo = new System.Diagnostics.ProcessStartInfo
{
    WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
    FileName = @"C:\Program Files (x86)\Microsoft SQL Server\<Version>\DAC\bin\SqlPackage.exe",
    Arguments = "/Action:Publish /SourceFile:C:/file.dacpac /TargetConnectionString:[Connection string]"
};
process.StartInfo = startInfo;
process.Start();
Sign up to request clarification or add additional context in comments.

6 Comments

is there still no way to deploy a dacpac (from .NET core) without calling the sqlpackage.exe?
@bytedev as I mentioned in answer keep an eye on github.com/Microsoft/DACExtensions/issues/20
I only asked cos your original answer is now 2.5 years old ;-)
As we can see at the moment DacFx .NET Core Support #20 is still Open
This answer should be updated as the GA package supporting .NET Core is out already. nuget.org/packages/Microsoft.SqlServer.DACFx
|
5

Good news as of Nov 15, 2018:

... the preview package which supports netcoreapp2.1 and net46: https://www.nuget.org/packages/Microsoft.SqlServer.DACFx/150.4240.1-preview

Be mindful it's the Microsoft.SqlServer.DacFx nuget package not the Microsoft.SqlServer.DacFx.x86 nor Microsoft.SqlServer.DacFx.x64 packages and you need to enable pre-release mode in nuget.

Discussed in the same thread:

https://github.com/Microsoft/DACExtensions/issues/20#issuecomment-439222493

Next up, I need to find out if it works...

Comments

3

Microsoft.SqlServer.DacFx nuget package is now released for netstandard2.0: https://www.nuget.org/packages/Microsoft.SqlServer.DacFx/

To publish a dacpac file to SQL Server LocalDB you can use:

using Microsoft.SqlServer.Dac;

...

var dacpac  = DacPackage.Load(@"path\to.dacpac");
var dacpacService = new DacServices("Server=(localdb)\\mssqllocaldb;Database=TargetDatabase;Trusted_Connection=True;MultipleActiveResultSets=true");
dacpacService.Publish(dacpac, "TargetDatabase", new PublishOptions());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.