ASP.NET MVC 5 DACPAC Sql140DatabaseSchemaProvider无效

问题描述 投票:0回答:1

当我从VS社区2017年5 MVC项目运行dacpac我得到这个错误。

"Internal Error. The database platform service with type Microsoft.Data.Tools.Schema.Sql.Sql140DatabaseSchemaProvider is not valid. You must make sure the service is loaded, or you must provide the full type name of a valid database platform service."

编码

            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
            }; 
            var dbServices = new DacServices(setupDbConn.ConnectionString);
            dbServices.Deploy(dp, newDatabaseName, true, dbDeployOptions);

此代码后的错误发生:

var dbServices = new DacServices(setupDbConn.ConnectionString);

我的SQLEXPRESS是2017年,我从再生SQLEXPRESS 2017年dacpac为好。该dacpac工作没有错误,当我在SQLEXPRESS使用它。

我一直在谷歌上搜索了几个小时,但似乎无法找到正确的答案。我想这是某种形式的兼容性问题,但无法弄清楚如何修正这个错误。

希望有人经历了这一点,并能帮助我解决这个问题。

asp.net-mvc-5 dacpac asp-net-mvc-1
1个回答
0
投票

我用尽了一切我能想到的。我已经安装了不同版本的dacfx的。也试过产生自2008年所有dacpac没有运气。

然后我使出其他的方式,而不是使用dacpac。我已经生成用于重建所有表的脚本并运行来代替。

Server myServer = new Server(serverName);

//Using windows authentication
bool integratedSecurity = Convert.ToBoolean(ConfigurationManager.AppSettings["integratedSecurity"]);    
myServer.ConnectionContext.LoginSecure = integratedSecurity;        
myServer.ConnectionContext.Connect();    

// check that database doesn't already exists
if (myServer.Databases.Contains(newDatabaseName))
{
    return new HttpStatusCodeResult(400, "Database has already been created");
}

//Define a Database object variable by supplying the server and the database name arguments in the constructor.   
Database db;
db = new Database(myServer, newDatabaseName);

//Create the database on the instance of SQL Server.   
db.Create();

string dbscript = System.IO.File.ReadAllText(Server.MapPath("~/assets/dbscript/createAllTables.sql"));    
myServer.Databases[newDatabaseName].ExecuteNonQuery(dbscript);
myServer.ConnectionContext.Disconnect();
© www.soinside.com 2019 - 2024. All rights reserved.