如何在 2013 SQL Server 数据库项目中为登录创建用户 [英] How to create a user for a login in 2013 SQL Server Database Project

查看:36
本文介绍了如何在 2013 SQL Server 数据库项目中为登录创建用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个具有 SSDT 数据库项目登录名的用户.登录名已存在于目标服务器上.使用以下 SQL:

I'm trying to create a user with a login for a SSDT database project. The login already exists on the target server. With the following SQL:

CREATE USER [MyLogin]
        FOR LOGIN [MyLogin]
        WITH DEFAULT_SCHEMA = dbo

GO

我收到错误:

错误 1 ​​SQL71501:用户:[MyLogin] 有一个对登录 [MyLogin] 的未解析引用.

Error 1 SQL71501: User: [MyLogin] has an unresolved reference to Login [MyLogin].

我找到了两种解决方案,但都不适用于 2013 年:

I've found two solutions, but neither work with 2013:

1) 创建一个服务器项目来引用登录.当前版本的 SSDT/VS2013 中没有此选项

1) Create a server project to reference the login. This isn't an option in the current version of SSDT / VS2013

2) 禁用模式检查.2013 年缺少该选项(我相信它是 Options -> Database Tools -> Schema Compare)

2) Disable schema checking. The option is missing in 2013 (I believe it was Options -> Database Tools -> Schema Compare)

推荐答案

您实际上可以使用标准 T-SQL 语法在 SQL Server 数据库项目中创建服务器级登录:

You can actually create the Server Level Login within the SQL Server Database Project using the standard T-SQL Syntax:

CREATE LOGIN [Login_Name] WITH PASSWORD = '<Password>';

注意:您也可以右键单击数据库项目并选择添加新项目"并导航到 SQL Server > 安全性(在模板对话框中)并选择登录(SQL Server)".

Note: You can also right-click the database project and choose 'Add New Item' and navigate to SQL Server > Security (within the templates dialog) and select 'Login (SQL Server)'.

这解决了 SQL71501 错误,并且(假设您使用 SQLPackage.exe 进行部署)将允许 SQLPackage.exe 在部署和发布之前将安全对象与目标数据库进行比较.

This resolves the SQL71501 Error and (assuming you are using SQLPackage.exe for deployment) will allow SQLPackage.exe the ability to compare the security object with the target Database before deployment and publishing occurs.

希望有帮助:)

这篇关于如何在 2013 SQL Server 数据库项目中为登录创建用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆