Solved

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

Posted on 2012-03-13
4
246 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
Comment Utility
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
Comment Utility
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
Comment Utility
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:ScottPletcher
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now