SSDT发布尝试删除和创建用户

时间:2019-04-20 01:05:06

标签: azure-sql-database sql-server-data-tools

在Visual Studio 2017中,我有一个带有使用SQL身份验证的简单数据库的SQL Server项目。

我正在尝试发布新表格。但是,发布脚本正在尝试删除并重新创建我用来发布数据库的用户。

GO
PRINT N'Dropping [adf]...';
GO
DROP USER [adf];
GO
PRINT N'Creating [adf]...';
GO
CREATE USER [adf] WITHOUT LOGIN;
GO
REVOKE CONNECT TO [adf];
GO
PRINT N'Creating <unnamed>...';
GO
EXECUTE sp_addrolemember @rolename = N'db_owner', @membername = N'adf';

CREATE TABLE ....

我阅读了View Preview:

** Highlights
     Tables that will be rebuilt
       None
     Clustered indexes that will be dropped
       None
     Clustered indexes that will be created
       None
     Possible data issues
       None

** User actions
     Drop
       [adf] (User)
     Create
       [adf] (User)
       [staging].[square_transactions] (Table)

** Supporting actions
     Create
       Role Membership: <unnamed> (Role Membership)

Your permissions to see all objects in the server or database could not be verified.  The original error was:
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. 
Reverse Engineer will continue the import process, and logins will not be imported.
The reverse engineering operation will attempt to continue anyway, but the resulting model might be incomplete, malformed, or incorrect.

我在登录名[adf]中添加了loginmanager角色,想知道这是否可以解决[adf]用户的删除和创建。没有。

最后,我使用服务器管理员帐户发布。它仍然会删除并创建用户,但至少能够运行。

如何解决此问题?我当时想我不应该使用服务器级别的admin帐户在SSDT / VS中进行数据库开发。

1 个答案:

答案 0 :(得分:0)

您还需要将Adf作为登录名添加到主数据库。您只需要在master上创建一次登录。请尝试以下操作:

----在服务器级别

CREATE LOGIN adf
    WITH PASSWORD = 'ThisIsAStrongPassword!' 
GO

----在主数据库级别创建用户

CREATE USER adf
    FOR LOGIN adf
    WITH DEFAULT_SCHEMA = dbo
GO
exec sp_addRoleMember 'dbmanager', 'adf';
exec sp_addRoleMember 'loginmanager', 'adf'

----在用户数据库中创建用户

CREATE USER adf
    FOR LOGIN adf
    WITH DEFAULT_SCHEMA = dbo
GO
exec sp_addRoleMember 'db_owner', 'adf';