[英]How to connect an existing SQL Server login to an existing SQL Server database user of same name
Is there a SQL Server command to connect a user of a single database to a login for the database server of the same name?是否有 SQL Server 命令将单个数据库的用户连接到同名数据库服务器的登录名?
For example:例如:
Database Server - Default Instance数据库服务器 - 默认实例
Database: TestDB数据库:TestDBServer Login - TestUser服务器登录 - TestUser
Existing user on TestDB - TestUser TestDB 上的现有用户 - TestUser
If I try to make the TestUser
login a user of the TestDB
database, the "User, group, or role" already exists.如果我尝试让TestUser
登录成为TestDB
数据库的用户,则“用户、组或角色”已经存在。
Does anybody know of an easy way to assign the DB user to the server login ?有人知道将数据库用户分配给服务器登录名的简单方法吗?
新方法(SQL 2008以后)是使用ALTER USER
ALTER USER OrphanUser WITH LOGIN = correctedLoginName;
I think it's sp_change_users_login
. 我认为这是sp_change_users_login
。 It's been a little while, but I used to do that when detaching and reattaching databases. 这已经有一段时间了,但在分离和重新连接数据库时我曾经这样做过。
我已经使用了sp_change_users_login
过程来完成那个场景。
if database is readonly: use the SID of the database user to create the login see: https://blog.sqlauthority.com/2015/04/18/sql-server-create-login-with-sid-way-to-synchronize-logins-on-secondary-server/如果数据库是只读的:使用数据库用户的 SID 创建登录见: https ://blog.sqlauthority.com/2015/04/18/sql-server-create-login-with-sid-way-to- 在辅助服务器上同步登录/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.