Link to home
Start Free TrialLog in
Avatar of denam
denam

asked on

Error 21002: [SQL-DMO] user already exists

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
ASKER CERTIFIED SOLUTION
Avatar of Mikhail Peterburgskiy
Mikhail Peterburgskiy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ColinSnelling
ColinSnelling

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.
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