/*============================================================================= 

re-create replication

Parameters
----------------------


Context
----------------------
ama707 (sql 2019)

Creation : 09.12.2022 / TSC
Modifications:

=============================================================================*/ BEGIN TRANSACTION 
USE [master]
GO
BEGIN TRANSACTION 

--#region drop replication subscription
EXEC [ActivePos_read].[dbo].[sp_dropsubscription] @publication = N'ActivePosTran', @article = N'all', @subscriber ='all'
EXEC [ActivePos_read].[dbo].[sp_droppublication] @publication = N'ActivePosTran'

--#endregion

--#region drop linked server
EXEC master.dbo.sp_dropserver @server=N'wam707a02', @droplogins='droplogins'
--#endregion

SELECT * 
FROM sys.[servers] [s]

--#region restart ActivePosClientService'
EXEC xp_cmdshell 'net stop ActivePosClientService '
EXEC xp_cmdshell 'net start ActivePosClientService '
--#endregion

--#region start job "backup"
EXEC msdb.dbo.sp_start_job   
     @job_name = 'D91030 - Backup ActivePos_Read'  
     ,@step_name = 'Purge old ActivePos_Read backups'
;
--#endregion

--#region repair replication
EXEC ActiveSystemServer.dbo.RepairReplication
--#endregion

SELECT * 
FROM sys.[servers] [s]

EXEC [ActivePos_server].dbo.[ExecuteOnAllPos]
    @query = 'select 1'    -- varchar(max)
   ,@nonQuery = 1 -- bit
   ,@timeout = 60  -- int


ROLLBACK TRANSACTION 

/* 
NET
    [ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP |
      HELPMSG | LOCALGROUP | PAUSE | SESSION | SHARE | START |
      STATISTICS | STOP | TIME | USE | USER | VIEW ]
*/