我的数据库中有一个用户没有相关的登录信息.它似乎是在没有登录的情况下创建的.
每当我尝试使用此用户连接到数据库时,我都会收到以下错误:
Msg 916, Level 14, State 1, Line 1
The server principal "UserName" is not able to access the database
"DatabaseName" under the current security context.
Run Code Online (Sandbox Code Playgroud)
我想为这个用户指定一个登录名,以便我可以实际使用它来访问数据库.我尝试了以下脚本将登录与用户关联起来.
USE [DatabaseName]
ALTER USER [UserName]
WITH LOGIN = [UserName]
Run Code Online (Sandbox Code Playgroud)
但这给了我以下错误:
Msg 33016, Level 16, State 1, Line 2
The user cannot be remapped to a login. Remapping can only be done for users
that were mapped to Windows or SQL logins.
Run Code Online (Sandbox Code Playgroud)
有什么办法可以为这个用户分配登录信息吗?我不想从头开始,因为这个用户有很多需要重新设置的权限.
编辑:回应Philip Kelley的问题,这是我跑步时得到的select * from sys.database_principals where name = …