?
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
Medium Priority
?
119 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
6 Comments
 
LVL 17

Accepted Solution

by:
dbaSQL earned 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

762 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