Sql-server – User not functioning after backup and restore of database to another server in SQL Server 2005

backupnetapprestoresql serversql-server-2005

We have a database called 'foo' on the first sql server instance called 'SQL01' that is backed up nightly via a snapshot with Snap Manager for SQL Server and then flex cloned and restored to a second server instance called 'SQL02'. In the database foo there is a sql user called 'someuser' that has datareader and stored procedure privileges.

After the restore operation I cannot access the foo database on SQL02 with the someuser user. I can see that the permissions appear to be set correctly for the user, but can't access the database. The error is "The server principal "someuser" is not able to access the
database "foo" under the current security context."

If I remove the user from the database and then add them again it works fine. Any ideas?

Best Answer

sp_change_users_login is old way of doing things and since you are using SQL Server 2005, try using ALTER USER syntax.

http://sqlblog.com/blogs/greg_low/archive/2009/02/02/much-ado-about-logins-and-sids.aspx

http://msdn.microsoft.com/en-us/library/ms176060.aspx