Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2008 -- User not able to access restored Database

I'm trying to move a database from one SQL Server database running on one machine to a another machine that is the test server and copy of the original.

On the main machine, I took a backup of database myDB. On the test machine, I deleted the existing older database myDB. On the test machine, I restored the new database myDB.

The data seems to have come across successfully. But I have a problem accessing the database. The owner of all tables is 'user1' and user1 exists with the same login on both DB's.

After trying to access the restored database on the test machine though as user1 there are problems. First it says that the password for user1 isn't correct. After resetting the password, it says the user1 doesn't have a default database set. But it is set already to myDB. It is the same name as the restored db -- myDB.

What have I done wrong in restoring the DB? Do I need to have deleted in addition to the DB the user user1 before attempting to restore the backup? I tried that. How do I handle updating a restore and maintaining user access?

like image 728
George Hernando Avatar asked Dec 01 '11 18:12

George Hernando


1 Answers

after doing the restore do a

ALTER USER user1 WITH LOGIN = user1

inside the restored DB, that will fix the mismapped SID

See also Do you still use sp_change_users_login instead of ALTER USER UserName WITH LOGIN = UserName

like image 195
SQLMenace Avatar answered Sep 25 '22 06:09

SQLMenace