使用数据库迁移发布ASP.NET Core Web应用程序失败,并在Visual Studio中出现以下错误
Web deployment task failed. (Make sure the database connection string for the server is correct and that you have appropriate permission to access the database. (Web Deploy Provider is "dbFullSql").
Error details:Could not complete an operation with the specified provider ("dbFullSql") when connecting using the Web Management Service. This can occur if the server administrator has not authorized the user for this operation. dbFullSql http://go.microsoft.com/fwlink/?LinkId=178034 Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_USER_NOT_AUTHORIZED_FOR_DBFULLSQL.)
从cmd行:
"C:\Dev\Neptune.Web\Neptune.Web.csproj" (default target) (1) ->
(MSDeployPublish target) ->
C:\Program Files\dotnet\sdk\2.1.300\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\PublishTargets\Microsoft.NET.Sdk.Publi
sh.MSDeploy.targets(139,5): error : Web deployment task failed. (Make sure the database connection string for the server is corr
ect and that you have appropriate permission to access the database. (Web Deploy Provider is "dbFullSql"). [C:\Dev\Neptune.Web\Neptune.Web.csproj]
C:\Program Files\dotnet\sdk\2.1.300\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\PublishTargets\Microsoft.NET.Sdk.Publish
.MSDeploy.targets(139,5): error : Error details:Could not complete an operation with the specified provider ("dbFullSql") when c
onnecting using the Web Management Service. This can occur if the server administrator has not authorized the user for this oper
ation. dbFullSql http://go.microsoft.com/fwlink/?LinkId=178034 Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERR
OR_USER_NOT_AUTHORIZED_FOR_DBFULLSQL.) [C:\Dev\Neptune.Web\Neptune.Web.csproj]
0 Warning(s)
1 Error(s)
如果我注释掉本地数据库连接字符串并使用连接字符串直接将更新应用于Azure SQL数据库(即直接在代码中连接到数据库),这就是奇怪的事情:#/ p>
C:\Dev\Neptune.Web>dotnet ef database update
Applying migration '20180613012042_CreateDate'.
Done.
我做过/检查的事情:
答案 0 :(得分:0)
根据你的描述,它太奇怪了。 以下是您可以参考的migratie existing asp.net core 2.0 application to asp.net core 2.1文章。
Managing database schema and seeding data with EF core migrations。
如果您想要apply migration at runtime,可以在Startup.cs
的配置方法中添加以下代码。
using (var scope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
{
scope.ServiceProvider.GetRequiredService<ApplicationDbContext>().Database.Migrate();
}
有关详细信息,请参阅此thread。