100 lines
2.4 KiB
Transact-SQL
100 lines
2.4 KiB
Transact-SQL
USE [HCITools]
|
|
GO
|
|
|
|
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Wait_For_LkSrv]') AND type in (N'P', N'PC'))
|
|
DROP PROCEDURE [dbo].[Wait_For_LkSrv]
|
|
GO
|
|
|
|
USE [HCITools]
|
|
GO
|
|
|
|
SET ANSI_NULLS ON
|
|
GO
|
|
|
|
SET QUOTED_IDENTIFIER ON
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
CREATE PROCEDURE [dbo].[Wait_For_LkSrv]
|
|
@in_debug tinyint = 0,
|
|
@in_LkSrv sysname,
|
|
@in_Minutes smallint = 30
|
|
AS
|
|
/*=============================================================================
|
|
|
|
Explication du traitement realise par la SP
|
|
-------------------------------------------
|
|
La SP sert à attendre que le Linked Server soit disponible
|
|
|
|
Contexte d'utilisation
|
|
----------------------
|
|
Appelé depuis n'importe quel job
|
|
|
|
Parametres
|
|
----------
|
|
@in_debug : non utilisé
|
|
@in_LkSrv : nom du Linked Server
|
|
@in_Minutes = Nombre de minutes maximal à attendre le Linked Server (30 par défaut)
|
|
|
|
Creation : 27.10.16 / FLA
|
|
|
|
Modifications :
|
|
|
|
=============================================================================*/
|
|
|
|
set nocount on;
|
|
|
|
/*------------------- Declaration des variables --------------------*/
|
|
declare @Datetime_For_Exit datetime,
|
|
@LkdSrv_is_OK int
|
|
|
|
|
|
/*------------ Affectation des parametres aux variables ------------*/
|
|
select @Datetime_For_Exit = dateadd(mi, @in_Minutes, getdate()),
|
|
@LkdSrv_is_OK = 0
|
|
|
|
/*-------------------------- Traitement ---------------------------*/
|
|
BEGIN TRY
|
|
|
|
|
|
/* ON ATTEND QUE LE LINKED-SERVER SOIT ATTEIGNABLE */
|
|
/* ET ON LAISSE TOMBER S'IL NE L'EST PAS AU BOUT DE X MINUTES */
|
|
while @LkdSrv_is_OK = 0
|
|
and getdate() < @Datetime_For_Exit
|
|
begin
|
|
BEGIN TRY
|
|
exec @LkdSrv_is_OK = sp_testlinkedserver @server = @in_LkSrv
|
|
;
|
|
/* SI ON EST ICI, C'EST BON !! */
|
|
select @LkdSrv_is_OK = 1
|
|
;
|
|
END TRY
|
|
BEGIN CATCH
|
|
/* ON ATTEND 5 MINUTES */
|
|
waitfor delay '00:05:00'
|
|
;
|
|
END CATCH
|
|
;
|
|
end /* while */
|
|
|
|
if @LkdSrv_is_OK = 0
|
|
begin
|
|
RAISERROR ('Error dans la SP Wait_For_LkSrv : Le linked-server est inaccessible.',16,1)
|
|
end
|
|
|
|
/*---------------------- Traitement des erreurs ----------------------*/
|
|
END TRY
|
|
BEGIN CATCH
|
|
|
|
/* Traitement des erreurs (avec RaiseError) */
|
|
EXEC dbo.get_Error_Info @in_RaiseError = 1
|
|
|
|
END CATCH
|
|
|
|
GO
|
|
|
|
|