Solved

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

Posted on 2012-03-13
4
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

623 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