June 7, 2006 at 3:53 am
SQL 2005
My problem is the user in a database is no longer in sync with the login. The login does not think it is mapped to the user. When i add the user it says it is already in the DB. When i try to delete the user it say i cant because it owns a schema. I cant delete the schema because all the objects in the DB belong to it??
What i think i need is a script to change the schema of every object so i can delete the schema and then the user and then add them back in hopefully syncing them with the login.
Used to be able to fix out of sync logins and users in 2000 by updating system tables but cant do that anymore and the adddition of schemas has made it worse.
Thanks,
June 7, 2006 at 4:56 am
Most probably you have done a restore. The user is there but not mapped to the current database.
In Users for current database, delete the user in mind. In Security, delete the user in mind.
Now, add the user as usual in Security.
N 56°04'39.16"
E 12°55'05.25"
June 7, 2006 at 5:00 am
June 8, 2006 at 11:13 am
In the context of the database you have restored....
sp_change_users_login 'update_one', '', ''
Check out BOL for more info on the sproc
June 8, 2006 at 11:55 am
Come on 'Jules', you remember this - it's the sysusers/syslogins SID disparity in SQL8. Listen to Sean.
Tim Wilkinson
"If it doesn't work in practice, you're using the wrong theory"
- Immanuel Kant
June 9, 2006 at 2:40 am
June 9, 2006 at 3:51 am
Unfortunatly its a windows NT login that has got out of sync and this sp doesnt update them. the code below coems from that SP. Any Ideas?
-- VALIDATE PARAMS --
-- Can ONLY remap SQL Users to SQL Logins! Should be no need
-- for re-mapping NT logins, and if you try, you'll mess up
-- the user status bits!
if not exists
(select name
from sysusers
where name = @UserNamePattern -- match user name
and issqluser = 1 -- must be sql user
and sid is not NULL
and len(sid) <= 16) -- must not be a sql-user for the database
begin
raiserror(15291,-1,-1,'User',@UserNamePattern)
return (1)
June 9, 2006 at 4:09 am
alter authorisation on schema <schname> to <newuser>
Tim Wilkinson
"If it doesn't work in practice, you're using the wrong theory"
- Immanuel Kant
June 9, 2006 at 5:14 am
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply