question

graz avatar image
graz asked

How to synchronize logins, etc. for database mirroring

We're just starting to use database mirroring at a client. Obviously we need to copy over logins, role memberships, jobs, etc. to the target machine on a regular basis. I looked at the SSIS task to do this and wasn't very impressed.

How are people doing this?

loginmirroring
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mrdenny avatar image
mrdenny answered

Either with an SSIS task, or setup a policy so that when an admin creates a login on one instance, that same login is created on the mirror instance as well.

You could also look into writing an T/SQL script which collects all the logins and then creates them on the remote system nightly by hacking up sp_help_revlogin and using that.

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

antxxxx avatar image
antxxxx answered

You will also need to ensure that the database users are mapped correctly to the logins on the server. Using this script when the mirror and principal swap roles should do it

declare @users table ( username sysname, usersid varbinary(85) )

declare @username sysname

insert into @users exec sp_change_users_login 'report'

declare user_cursor cursor for select username from @users

open user_cursor

fetch next from user_cursor into @username

while (@@fetch_status = 0) begin exec sp_change_users_login 'auto_fix', @username fetch next from user_cursor into @username end

close user_cursor deallocate user_cursor

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jason Cumberland avatar image
Jason Cumberland answered

I use a script and linked server to do this, running from a daily Agent job. This synchs up the password for SQL accounts and keeps the SID the same, similar to sp_help_revlogin.

post: http://qcumberland.com/index.php/archives/2009/07/20/synching-logins-between-2-instances/

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.