Bonjour,
J'ai une application d'archivage qui scan et importe les fichiers présents dans un dossier.
Lors de l'importation, cette application exécute un INSERT dans sa base de donnée (Table FILE)
J'ai un Trigger On Insert actif sur cette table car j'aimerai mettre à jour une autre table pour assurer un suivi.
Cependant, lorsque j'exécute la moindre requête dans mon trigger, celui-ci recommence sa procédure à zéro.
Est-ce du au rescan du folder ? Ou un problème de mon trigger ?
Voici un extrait de code :
USE [SdArchive]
GO
/****** Object: Trigger [dbo].[FileFullInsertTrigger] Script Date: 19/12/2019 09:30:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[FileFullInsertTrigger] ON [dbo].[File]
FOR INSERT
AS
BEGIN
SET NOCOUNT ON
DECLARE
@GetDt as smalldatetime,
@GetMsgSmartDocID as bigint,
@GetAttSmartDocID as bigint,
@GetAddInID as bigint,
@GetProLkID as bigint,
@GetChkSum as nvarchar(50),
@fileName as nvarchar(300),
@splitFile as varchar(30),
@userName as nvarchar(300),
@nbAttachment as int,
@logTexte as nvarchar(500),
@count as int
BEGIN
SET NOCOUNT ON
IF ((SELECT COUNT(*) FROM inserted) = 1)
BEGIN
SET NOCOUNT ON
IF ((SELECT [Extension] FROM inserted) = '.msg')
BEGIN
SET NOCOUNT ON
exec xp_logevent 50001 , '#.MSG'
SET @GetMsgSmartDocID = (Select [ID] From inserted)
SET @GetChkSum = (Select [Checksum] From inserted)
exec xp_logevent 50001 , @GetMsgSmartDocID
exec xp_logevent 50001 , @GetChkSum
SET NOCOUNT ON
SET @count = (Select count(*) From SstArchive.dbo.AddInMail Where SstArchive.dbo.AddInMail.MsgCheckSum=@GetChkSum)
exec xp_logevent 50001 , '#.MSG : count(*)'
exec xp_logevent 50001 , @count
IF @count = 1
BEGIN
exec xp_logevent 50001 , '#.MSG : Update'
END
ELSE
BEGIN
exec xp_logevent 50001, '#.MSG : Pas de référence en attente dans SST > AddIn'
exec xp_logevent 50001, '#.MSG : importé mais non lié à une pièce jointe'
END
END
ELSE
BEGIN
exec xp_logevent 50001, '#.ATT'
END
END
END
END