Advertisement

05.07.2008 at 03:42AM PDT, ID: 23382255
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

How do I add the dbo user to a sql login user map?

Asked by Mehuge in SQL Server 2005

Tags: , ,

Background:

Developing a script to replicate two databases from one SQL Server 2005 Express to another on a nightly basis.  The approach I am taking to achieve this is to perform a nightly backup of the master database, and transfer and restore tha backup on the mirror server.  This ofc means that I need to sort out the orphaned users, which for the most part is working, except for the dbo user.

This is what I am doing currently to restore each database

ALTER DATABASE [db1] SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE
RESTORE DATABASE [db1] FROM DISK = N'\path\to\db1.bak'
USE [db1]
EXEC sp_change_users_login 'update_one','user1','user1'
EXEC sp_change_users_login 'update_one','user2','user2'

However when I come to try and restore the dbo login to user2 which is how its mapped on the master

EXEC sp_change_users_login 'update_one','dbo','user2'

I get the error

Msg 15287, Level 16, State 1, Procedure sp_change_users_login, Line 35
Terminating this procedure. 'dbo' is a forbidden value for the login name parameter in this procedure.

Well for starters, I didnt pass dbo as the login name its passed as the username, which led to some confusion at first, but it seems I am not allowed to reconnect dbo user to its login in this way.  So I instead do.

EXEC sp_changedbowner 'user2'

And the dbo user is now connected to its login.  However, the user2 login on the live server also has the following mappings

db1 User=dbo    Default Schema=dbo
db2 User=user2 Default Schema=dbo

and on the restored mirror, the first mapping is lost, so I need to re-apply it, but when I try:

CREATE USER [dbo] FOR LOGIN [user2]

it complains that user dbo already exists, which ofc it does.

Right, so the question is:

How do I re-create user mapping between the user2 login and the db1/dbo user?Start Free Trial
 
 
[+][-]05.07.2008 at 07:06AM PDT, ID: 21516485

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: SQL Server 2005
Tags: Microsoft, SQL Server, 2005 Express
Sign Up Now!
Solution Provided By: Julianva
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.07.2008 at 07:47AM PDT, ID: 21516988

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628