Solved

Need help restoring a SQL database to test env.  user returns no name or sid

Posted on 2012-03-13
4
255 Views
Last Modified: 2012-03-27
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.
0
Comment
Question by:tenover
  • 2
4 Comments
 
LVL 7

Expert Comment

by:micropc1
ID: 37718422
You may have some orphaned users. Do the following to check and fix...

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'
0
 

Author Comment

by:tenover
ID: 37718458
Thanks.  
The first query returns nothing.
The second query runs and reports "0" changes......
0
 
LVL 7

Accepted Solution

by:
micropc1 earned 500 total points
ID: 37718475
Make sure you selected the restored database first. If the first query doesn't return anything that means there's nothing to fix and the problem is elsewhere. Orphaned users are pretty common after restoring a database, so it was worth a shot...

More info here... http://msdn.microsoft.com/en-us/library/ms175475.aspx
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 37721212
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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question