?
Solved

Error 21002: [SQL-DMO] user already exists

Posted on 2002-05-10
3
Medium Priority
?
19,888 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
[X]
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
3 Comments
 
LVL 1

Accepted Solution

by:
Mikhail Peterburgskiy earned 800 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

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.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

741 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