Solved

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

Posted on 2012-03-13
4
252 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

786 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