tenover
asked on
Need help restoring a SQL database to test env. user returns no name or sid
We have a production environment and a test environment. I restored the production database to the test environment (SQL 2005 on both). Before I did this, I grabbed the sid of the database owner. When I go in to the test environment and try to add the same user with the same sid (sp_addlogin '<login_name>', '<password>', '<database_name>', '<language>', sid) it completes successfully, however when I do a search for that user using:
select name, sid from sysusers where name='<login_name>', it returns empty fields for the username and sid. This, I believe is stopping me from successfully connecting to the database from the application. Any suggestions???? Need to get this resolved ASAP. Thanks in advance.
select name, sid from sysusers where name='<login_name>', it returns empty fields for the username and sid. This, I believe is stopping me from successfully connecting to the database from the application. Any suggestions???? Need to get this resolved ASAP. Thanks in advance.
ASKER
Thanks.
The first query returns nothing.
The second query runs and reports "0" changes......
The first query returns nothing.
The second query runs and reports "0" changes......
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Stay away from AUTO_FIX, it can falsely link logins and users. Use UPDATE_ONE instead, and explicitly tell SQL which login to link to which userid.
See if this returns anything:
SELECT *
FROM sys.database_principals
WHERE
principal_id > 4 AND
sid IS NULL
See if this returns anything:
SELECT *
FROM sys.database_principals
WHERE
principal_id > 4 AND
sid IS NULL
The following will list any any orphaned users in the database
EXEC sp_change_users_login 'Report'
If you've already re-created a corresponding SQL account, run the following to fix it automatically...
EXEC sp_change_users_login 'Auto_Fix', 'user'
If you haven't created an account, you can do so and fix the orphaned user by running this...
EXEC sp_change_users_login 'Auto_Fix', 'user', 'login', 'password'