473,394 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Question: re-associate dbo with sa??

BD
Hi all.

Running SQL2K SP4 on W2K3 Standard, SP4.

I have just refreshed a database on one server with a backup from
another. The database had existed previously on the target server, and
I am just refreshing its contents. I used the following approach

1) From the target server, create a SQL script with users and roles
2) From the source server, back up the db
3) Transfer the file
4) Restore the db, checking the location of the data and log files to
ensure correctness
5) Remove orphaned users
6) Run in the users/roles script generated in step 1
7) Run in a canned script containing object-level grants.

I've done this dozens of times in other databases, but something a
little unusual has occurred here:

My dbo user is orphaned. Normally it's associated with the 'sa' login,
but at this point there is no associated user.

I can see why this has happened - on the source db, the dbo user has
been associated with a non-default login.

And, many of the objects in the db are owned by dbo.

The only viable option I see is to change the ownership of these
objects, drop dbo, re-add it with the association to sa, and reassert
the object-level grants.

But what I would prefer is some way to change the association of the
dbo user, to associate it with 'sa' without the need to drop and
recreate.

Can anyone suggest an alternative strategy to associate a login and a
user after-the-fact?

Thanks much for all input!

BD

Dec 27 '06 #1
4 15620
But what I would prefer is some way to change the association of the
dbo user, to associate it with 'sa' without the need to drop and
recreate.
The login mapping for the 'dbo' user is determined by database ownership.
You can execute sp_changedbowner to change/fix the database owner:

USE MyDatabase
EXEC sp_changedbowner 'sa'

--
Hope this helps.

Dan Guzman
SQL Server MVP

"BD" <ro*********@gmail.comwrote in message
news:11**********************@f1g2000cwa.googlegro ups.com...
Hi all.

Running SQL2K SP4 on W2K3 Standard, SP4.

I have just refreshed a database on one server with a backup from
another. The database had existed previously on the target server, and
I am just refreshing its contents. I used the following approach

1) From the target server, create a SQL script with users and roles
2) From the source server, back up the db
3) Transfer the file
4) Restore the db, checking the location of the data and log files to
ensure correctness
5) Remove orphaned users
6) Run in the users/roles script generated in step 1
7) Run in a canned script containing object-level grants.

I've done this dozens of times in other databases, but something a
little unusual has occurred here:

My dbo user is orphaned. Normally it's associated with the 'sa' login,
but at this point there is no associated user.

I can see why this has happened - on the source db, the dbo user has
been associated with a non-default login.

And, many of the objects in the db are owned by dbo.

The only viable option I see is to change the ownership of these
objects, drop dbo, re-add it with the association to sa, and reassert
the object-level grants.

But what I would prefer is some way to change the association of the
dbo user, to associate it with 'sa' without the need to drop and
recreate.

Can anyone suggest an alternative strategy to associate a login and a
user after-the-fact?

Thanks much for all input!

BD
Dec 28 '06 #2
BD
USE MyDatabase
EXEC sp_changedbowner 'sa'

--
Hope this helps.

Thanks, Dan - I expect it will.

Out of curiosity, though - I presume that dbo is unique in this regard
- ie., if the same thing had happened with a different ID, I'd have to
reassociate it 'the hard way'... ?

Dec 28 '06 #3
BD (ro*********@gmail.com) writes:
Out of curiosity, though - I presume that dbo is unique in this regard
- ie., if the same thing had happened with a different ID, I'd have to
reassociate it 'the hard way'... ?
Yes and no. That is dbo is he only you can fix with sp_changedbowner.
The others you can fix with sp_change_users_login. This is a little
less painful and dropping the users, since you don't lose permissions
and that.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Dec 28 '06 #4
BD
The others you can fix with sp_change_users_login.

Oh, perfect. Thanks for that. I will find that very useful, as it turns
out there are several orphaned users on this system.

Cheers,

BD

Dec 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dave Cooke | last post by:
Hi, I have developed a website that uses Sessions to manage user state. It has come to my attention that the users that will be using this site do not want to enable cookies on their machines....
4
by: Joe | last post by:
The recipe in question is "Implementing Static Methods". It shows how to use staticmethod(). This sentence in the Discussion section isn't clear to me: "An attribute of a class object that...
4
by: Chris Strug | last post by:
Hi, Probably a very simple question but I'm afraid my experience at this is somewhat limited so... In a database with a many to one relationship, say orders to customers, is it preferable to...
7
by: CT | last post by:
Hi, This might seem like a basic question but I have some doubts, please humour me. I have a client-server application using java where each client on each machine needs to directly...
5
by: sea | last post by:
I have 2 applications, one a Microsoft Visual Basic application and the other a Java application both connecting to the same DB2 database. The database has binary LOB objects. The Visual Basic...
0
by: Terry-OMAF | last post by:
I'm trying to create a web service in C# to populate a drop down in MS InfoPath with Active Directory users. How do I return what's found (if possble please provide code)? Not sure ift's the...
0
by: Mike hofer | last post by:
I am studying up for my MCAD, and came across an interesting conundrum. According to my textbook, there are FOUR steps to publish an event: 1. Define a delegate type that specifies the prototype...
7
by: Bernie Yaeger | last post by:
I can't believe that there aren't lots of developers who: 1. create a crystal report that connects to sql server 2. calls the report using the crystalreportviewer control to view it and then,...
1
by: Frank Millman | last post by:
Hi all I am developing a multi-user business/accounting application. It is coming along nicely :-), though rather slowly :-( I have hit an issue which will require a lot of changes to the code...
1
by: Steve Marshall | last post by:
Hi all, This is probably a real dumb question, but I just haven't come across the answer... Is there a simple way to treat a byte array as a string, or to convert it to a string? And the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.