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
112 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to just get time from a date 6 32
Negative isnull? 3 14
Dynamic SQL select query 4 36
Use column to search string column 2 9
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

840 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