User login problem after restoring DB in MSSQL 2005

After doing a restore of a DB from file it can happened that the database users are no longer linked with the servers login users. This problem will result in a db user being able to log in but not to access the databases.

To check for problem use the following code, change TargetDB to the target database and username with the user.

use master
go
select name as sqllogin,sid as serversid from sys.syslogins where [name] = 'username'

use TargetDB
go
select name as databaseid, sid as databasesid from sysusers where [name] = 'username'
go

use TargetDB
go
sp_change_users_login @Action='Report'
go


Compare serversid and databaseid, if not equal then run

use TargetDB
go
sp_change_users_login @Action='update_one',
@UserNamePattern='username',
@LoginName='username'
go


Read more here

Comments

Post a Comment

Popular posts from this blog

How to disable auto enabled flight key using KillSwitch

Technical intro to Feature management in D365FO

Continuous integration and deployment Power platform FinOps tweaking