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
Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 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