March 1, 2016 at 9:51 am
Hi
Here is the issues. I am unable to use Power Shell for security reasons, and I need a script to run after a failover. The script updates a table in one of the database to allow a third party app to connect on the new server that the database has failed over to. The script is simple
update ReportDatabase set RprtDtbseSrvr = @@SERVERNAME;
Go
How do I do this without Power Shell.
March 3, 2016 at 7:35 am
I haven't tried it, so it's just an idea. Have you tried scheduling a SQL Server Agent job at 'SQL Server Agent Startup'?
March 3, 2016 at 12:06 pm
Can you configure the third party app to point to the "SQL Server Network Name"?
March 3, 2016 at 3:19 pm
You could setup a SQL Agent job on each replica to run the following:
DECLARE @ServerName NVARCHAR(256) = @@SERVERNAME
DECLARE @RoleDesc NVARCHAR(60)
DECLARE @AGName NVARCHAR(256) = 'YourAGNameHere'
SELECT @RoleDesc = rs.role_desc
FROM sys.dm_hadr_availability_replica_states rs
JOIN sys.availability_replicas r
ON rs.replica_id=r.replica_id
JOIN sys.availability_groups ag
ON rs.group_id=ag.group_id
WHERE r.replica_server_name = @ServerName
AND ag.name = @AGName
IF @RoleDesc = 'PRIMARY'
BEGIN
UPDATE ReportDatabase SET RprtDtbseSrvr = @@SERVERNAME;
END
March 3, 2016 at 3:22 pm
I'm not sure how "good" of a solution it is, but we've had success by creating a SQL Server Agent alert on Error number 1480 (Database replica role change) on all databases. We have it fire off a SQL job, and e-mail our DBA team.
You'll need that alert set up on your primary and secondary replica(s).
To avoid having both inadvertently fire in the case of a manual failover (or any other failover where both instances stay up), we have the jobs wait 2 minutes (WAITFOR DELAY '00:02:00'), and then wrap the job tasks in an if statement so they only run if they are the primary.
IF (SELECT MASTER.DBO.FN_AG_IsPrimary('<AG NAME>')) = 1
BEGIN
-- DO YOUR FAILOVER STEPS
END
You may need to tweak your delay longer or shorter depending on your environment and needs, but for us we seem to be pretty solid with our setup.
The Redneck DBA
March 3, 2016 at 4:00 pm
Is this for alwayson failover cluster or alwayson availability groups?
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply