Solved

Error 21002: [SQL-DMO] user already exists

Posted on 2002-05-10
3
19,779 Views
Last Modified: 2011-08-18
hi all

i restored a database called db1

owner of the tables in this database is "owner1" but in my sqlserver "owner1" doesn't
exist.=20 so i create a user "owner1"

when i check the box "db1 can be accessed by owner1", i got this error : = "Error 21002: [SQL-DMO] user owner1 already exists."

what can i do?

Thanks
0
Comment
Question by:denam
3 Comments
 
LVL 1

Accepted Solution

by:
Mikhail Peterburgskiy earned 200 total points
ID: 7003020
I had similar problem when restored db from one server to another.  I fixed it using sp_change_users_login

From MSDN:
sp_change_users_login
Changes the relationship between a Microsoft® SQL Server™ login and a SQL Server user in the current database.

Syntax
sp_change_users_login [ @Action = ] 'action'
    [ , [ @UserNamePattern = ] 'user' ]
    [ , [ @LoginName = ] 'login' ]

You can find documentation in MSDN online
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sp_ca-cz_8qzy.asp
0
 
LVL 1

Expert Comment

by:ColinSnelling
ID: 7005820
sp_change_users_login only works with SQL Server logins.

This is if you use NT logins :

There is a link between the users in a database (stored in sysusers) and the logins (syslogins) on the sid field.  I'm pretty sure this contains the Windows sid (security id) not a SQL Server one.  Say we have a user ColinS in database db1 and this is linked to NT login MyDomain\ColinS.  If you restore a database from another server and this database was a user ColinS but linked to LocalServer\ColinS then although the users are the same there is no link between sysusers and syslogins.

Enterprise Manager in SQL 7 still showed the user so it was easy to delete.  Enterprise Manager in SQL 2000 doesn't so you have to look at sysusers in Query Analyser and then use sp_revokedbaccess to remove the offending user.
0
 

Expert Comment

by:muktamariwala
ID: 11150093
I am trying to attach a database to a new sql server onwhich the userid already exists.However this useris the ownerof sometables intehdatabase.
when Irun a select query "select * from employee" for eg. it says Invalid object name.
However if i write the query like this::
"select * from username.employee" then it works even though I logged in with username.
When i try to associate this user withdatabase access it gives error"username already exists"
Kindly give the solution
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

813 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