发布到Azure时出错
我正试图发布对Azure应用程序服务的一些更改,包括数据库迁移,但我遇到了以下错误。有人知道这是怎么回事吗。 另外,数据库用户没有分配sysadmin服务器角色发布到Azure时出错,azure,visual-studio-2017,azure-sql-database,Azure,Visual Studio 2017,Azure Sql Database,我正试图发布对Azure应用程序服务的一些更改,包括数据库迁移,但我遇到了以下错误。有人知道这是怎么回事吗。 另外,数据库用户没有分配sysadmin服务器角色 1>Warning SQL0: A project which specifies SQL Server 2016 as the target platform may experience compatibility issues with Microsoft Azure SQL Database v12. 1>War
1>Warning SQL0: A project which specifies SQL Server 2016 as the target
platform may experience compatibility issues with Microsoft Azure SQL
Database v12.
1>Warning SQL0: Your permissions to see all objects in the server or
database could not be verified. The original error was:
1>The SELECT permission has not been granted on 'sys.sql_logins' for the
'master' database. You must be a member of the 'loginmanager' role to access
this system view.
1>Reverse Engineer will continue the import process, and logins will not be
imported.
1>The reverse engineering operation will attempt to continue anyway, but the
resulting model might be incomplete, malformed, or incorrect.
1>Error SQL72014: .Net SqlClient Data Provider: Msg 5011, Level 14, State 2,
Line 5 User does not have permission to alter database 'Iklikl_Staging', the
database does not exist, or the database is not in a state that allows
access checks.
1>Error SQL72045: Script execution error. The executed script:
1>IF EXISTS (SELECT 1
1> FROM [sys].[databases]
1> WHERE [name] = N'$(DatabaseName)')
1> BEGIN
1> ALTER DATABASE [$(DatabaseName)]
1> SET TEMPORAL_HISTORY_RETENTION ON
1> WITH ROLLBACK IMMEDIATE;
1> END
您需要以SQLAzure为目标 : 更改项目的目标平台 在解决方案资源管理器中的项目上单击鼠标右键,然后选择“属性”。单击左侧的“项目设置”选项卡以访问“项目设置”属性页
此页面中的目标平台下拉列表包含数据库项目可以发布到的所有受支持的SQL Server平台。对于此过程,请选择SQL Azure。用于部署的SQL用户不属于
loginmanager
角色loginmanager
和dbmanager
是Azure SQL独有的两个角色
对主机运行以下命令(其中[user]
是您的sql用户):
通过运行以下查询,您可以验证您的用户现在是否属于正确的角色:
select dp.name as db_role, dp2.name as db_user
from sys.database_role_members drm
join sys.database_principals dp on (drm.role_principal_id = dp.principal_id)
join sys.database_principals dp2 on (drm.member_principal_id = dp2.principal_id)
order by dp.name
用户可能还需要其他权限,如“Alter”、“Select”和“View Definition”,您可以通过对数据库运行以下示例命令来添加这些权限(其中,[user]
是您的sql用户):
GRANT ALTER TO [user]
以下是我使用的文章(迪福阅读了第一篇,后两篇补充了其中的信息):
这不是一个数据库项目,而是一个MVC web应用程序,我一直在成功发布,直到我为它编写了迁移。您的答案是否仍然有效,因为我在“设置”页面中没有看到任何包含目标平台的下拉列表。这些错误与您的MVC应用程序无关。它们都与数据库相关。如果您已开发在本地SQL上运行,并希望部署到Azure SQL,因此它们非常相似,但不相同。此处记录了将Azure SQL迁移到on-prem SQL的过程。我对实体使用代码优先的方法,尝试在OP中执行脚本时出错,我可以使用SQL Server Management Studio创建、更改和删除远程发布,但当我试图通过VisualStudio发布它时,会出现上述错误,现在我不知道它是与数据库权限相关还是与其他内容相关。
GRANT ALTER TO [user]