授予对数据库的SQL Server登录访问权限 - SQL Server [英] Granting a SQL Server Login Access to a Database - SQL Server

查看:467
本文介绍了授予对数据库的SQL Server登录访问权限 - SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为SQL Server登录授予访问数据库的权限。我知道sp_grantdbaccess,但它已被弃用。

I want to grant access to a database for a SQL Server login. I know about sp_grantdbaccess, however it is deprecated. What can I use instead and how can I check if the login does not already have access to the database?

场景:UserA创建数据库 - 在sys.database_principals中我有一个可以访问数据库的脚本条目,名称为dbo,并带有UserA的sid。我尝试再次授予UserA许可:我尝试在sys.database_principals通过name ='UserA'做一个选择,但是由于名称是dbo不是UserA,我得到一个错误 - '登录已有一个帐户下不同的用户名。'。

Scenario: UserA creates database - in sys.database_principals I have an entry with name dbo and with the sid of UserA. I try to grant UserA permisions again: I try to do a select on sys.database_principals by name='UserA', however since name is dbo not UserA, I get an error - 'The login already has an account under a different user name.'. How can I determine if the user has database access without the sid?

推荐答案

您可能需要 CREATE USER

例如

CREATE USER bobuser FOR LOGIN boblogin

sys.database_principals 安全性目录具有数据库用户的列表,因此您可以确保您没有该名称的一个。

The sys.database_principals security catalog has a list of the database users, so you can ensure you don't already have one with that name.

这篇关于授予对数据库的SQL Server登录访问权限 - SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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