-->

.Net MVC deploy a dacpac

2019-08-17 08:59发布

问题:

I'm trying to do deploy dacpac. I'm having errors though when running below code.

            var dacpacName = "Setup.dacpac";
            var dacpacPath = Path.Combine(Server.MapPath("~/assets/dacpac"), dacpacName);

            var dp = DacPackage.Load(dacpacPath);
            var dbDeployOptions = new DacDeployOptions
            {
                BlockOnPossibleDataLoss = false,
                ScriptDatabaseOptions = false,
                GenerateSmartDefaults = true,
                CreateNewDatabase = true
            };

When running the code I'm encountering the error:

The type initializer for 'Microsoft.SqlServer.Dac.DacPackage' threw an exception.

This happens just right after the:

 var dp = DacPackage.Load(dacpacPath);

My path is:

var dacpacPath = Path.Combine(Server.MapPath("~/assets/dacpac"), dacpacName);

So the path is pointing to the exact location of the dacpac file but it's not working.

回答1:

Found the answer to my question from https://social.msdn.microsoft.com/Forums/sqlserver/en-US/ced08955-1d00-48cd-a3fc-905e4fd07f43/error-installing-dacpac-using-sqlpackageexe?forum=ssdt

I search the ff from nuget and installed it, and the error is gone.

  • T-SQL ScriptDom
  • SQLSysCLRTypes

Thanks,