Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Analyzer
Posting Yak Master
115 Posts |
Posted - 2008-03-27 : 12:20:15
|
| When restoring DBs to other environments the SIDS don't transfer causing access problems, and when I use a SID scripting method and deploy on the target environment SQL says the login already exists.I usually end up with the cumbersome process of explicitly removing the logins and re-applying - how to other DBA's get round this? |
|
|
sqldba20
Posting Yak Master
183 Posts |
Posted - 2008-03-27 : 12:27:12
|
| You can run this against your restored database and this will fix the users.BEGINDECLARE @username varchar(255)DECLARE fixusers CURSORFORSELECT UserName = name FROM sysusersWHERE issqluser = 1 and (sid is not null and sid <> 0x0)and suser_sname(sid) is nullORDER BY nameOPEN fixusersFETCH NEXT FROM fixusersINTO @usernameIF @@FETCH_STATUS <> 0 --no users to fix but set dbo just incaseBEGINEXEC sp_changedbowner 'sa'ENDWHILE @@FETCH_STATUS = 0BEGINIF @username='dbo'BEGINEXEC sp_changedbowner 'sa'ENDELSEBEGINEXEC sp_change_users_login 'update_one', @username, @usernameENDFETCH NEXT FROM fixusersINTO @usernameENDCLOSE fixusersDEALLOCATE fixusersEND |
 |
|
|
Analyzer
Posting Yak Master
115 Posts |
Posted - 2008-03-28 : 05:35:41
|
| Thanks - i will test immediately |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
|
|
|
|
|