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
114 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 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

733 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