Solved

T-SQL script to automate the process of transferring SQL server 2005 login from SQL server 2005 mirror primary site to DR site

Posted on 2014-09-23
6
106 Views
Last Modified: 2015-04-23
Dear all,

I have a script to automate the process of transferring SQL server 2005 login from SQL server 2005 mirror primary site to DR site, see attached.

but it doesn't take care the transfer or change of login status ( disabled/deleted).

see the statement here:

	If Not Exists (Select 1 From sys.server_principals
				Where name = @LoginName)

Open in new window


so it only copy new login but not any altered login and deleted login,

any way to improve it ?
dba-CopyLogins.sql
0
Comment
Question by:marrowyung
  • 5
6 Comments
 
LVL 17

Accepted Solution

by:
dbaSQL earned 500 total points
ID: 40342624
>>so it only copy new login but not any altered login and deleted login,

I'm not sure if I follow you exactly, but if you've deleted a login, there isn't one to copy.  Are you saying that if you delete a login, you want that action to also occur on the mirror server?

If that is what you mean, you probably need to revise your script to first compare the logins between the Principal and the Mirror.  Then, of course, if there is no match at the principal, you can assume the login may be removed from the mirror.    

A slightly more complex, but potentially safer, method would be a database trigger that fires when the DROP LOGIN is run on the Primary.  These logins could be written to a table within a DBA administrative-type database, which could then be referenced to perform the same action in the Mirror.

I say 'safer' because this allows you to review the login actions -- delete or alter -- before pushing the changes to the Mirror.  


Same principal could be used for the 'altered' logins.
0
 
LVL 1

Author Comment

by:marrowyung
ID: 40343396
"I'm not sure if I follow you exactly, but if you've deleted a login, there isn't one to copy.  Are you saying that if you delete a login, you want that action to also occur on the mirror server?"

yes sure ! that's why I am going to inprove this script further, that scritp can handle new login and disabled login but not deleted login

"
 A slightly more complex, but potentially safer, method would be a database trigger that fires when the DROP LOGIN is run on the Primary. "

Already has a plan but for that script, has to run on DR server, I can't trigger it from primary server. can I make the trigger to execute the Script/sp  located on DR server ?

"These logins could be written to a table within a DBA administrative-type database, which could then be referenced to perform the same action in the Mirror.
"
The while loop in the script already doing this!  but temp table.

"I say 'safer' because this allows you to review the login actions -- delete or alter -- before pushing the changes to the Mirror."

I don't understnad why and what it means, please say it again.
0
 
LVL 1

Author Comment

by:marrowyung
ID: 40343480
if  I create a SP by that script on the DR mirror server, can I call that remote SP from mirror primary server like that by DDL trigger so that whenever a new login added/altered, the remote SP fire out and get new login from primary server?

Create Trigger CopyLoginsToDestination
On All Server
After Create_Login, Alter_Login
As
exec <mirror DR partner serer>.master.dbo.dba_CopyLogins 

Open in new window


will it works in this way ?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Author Comment

by:marrowyung
ID: 40343496
by the way, is the create trigger statment works?


Should be

On Server 

Open in new window


instead of

On All Server

Open in new window


right?
0
 
LVL 1

Author Comment

by:marrowyung
ID: 40615865
please reply to this.
0
 
LVL 1

Author Closing Comment

by:marrowyung
ID: 40741741
tks.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how the fundamental information of how to create a table.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now