2009-07-31 10 views
0

J'exécute une «tâche SQL d'exécution» dans SSIS Il exécute une procédure stockée qui effectue une validation Dans la procédure stockée, j'ai une commande RAISERROR en cas de problème. Cependant, lorsque j'effectue un test, cette tâche échoue. J'ai cherché sur Google à ce sujet et trouvé beaucoup de références, mais pas de solution qui fonctionne pour moi. J'ai mis à niveau SQL Server 2005 vers Service Pack 3, mais cela ne fait aucune différence. Une référence suggère de mettre des instructions PRINT lorsqu'une exception est levée. Cela ne fonctionne pas. Alors, comment puis-je résoudre ce problème? Le code dans la procédure stockée est;SSIS (SQL Server 2005) Ne pas intercepter l'exception SQL

ALTER PROCEDURE [dbo].[usp_VAL_Journey] 
AS 
BEGIN 
    -- SET NOCOUNT ON added to prevent extra result sets from 
    -- interfering with SELECT statements. 
    SET NOCOUNT ON; 

    DECLARE @Month AS INT 
        , @Year AS INT 
    SELECT TOP 1 @Year = DATEPART(YEAR, Date), @Month = DATEPART(MONTH, Date) 
      FROM dbo.JourneyLandingTable 

    SELECT TOP 1 * 
      FROM dbo.JourneyMasterTable 
      WHERE DATEPART(YEAR, Date) = @Year 
      AND DATEPART(MONTH, Date) = @Month 
    IF @@ROWCOUNT > 0 
    BEGIN 
      RAISERROR('JourneyMasterTable already contains data for this month.', 16, 1) 
      RETURN 
    END 

    SELECT DATEPART(YEAR, Date) AS year1, DATEPART(MONTH, Date) AS month1 
    FROM dbo.JourneyLandingTable 
    GROUP BY DATEPART(YEAR, Date), DATEPART(MONTH, Date) 

    IF @@ROWCOUNT > 1 
    BEGIN 
      RAISERROR('JourneyLandingTable contains data for more than 1 month.', 16, 1) 
    END 
END 

Répondre

0

J'ai une chose similaire mais fonctionne bien pour moi. Je ne sais pas pourquoi ça ne marche pas. La configuration que j'ai est je ne soulève pas d'erreur à divers endroits. Je continue d'incrémenter le nombre d'erreurs et je l'augmente finalement comme suit. Cela fonctionne parfaitement - il abandonne l'exécution et tout ce qui est bien.

declare @errorString varchar(100) 
IF @rc > 0 
BEGIN 
    set @errorString = 'Error(s) occured when trying to run sp_blahblah error count ' + cast(@rc as varchar(10)) 
    raiserror(@errorString , 16, 1) 
END 
0

vous pouvez essayer de retourner une valeur « RETOUR n »

ALTER PROCEDURE [dbo].[usp_VAL_Journey] 
AS 
BEGIN 
    -- SET NOCOUNT ON added to prevent extra result sets from 
    -- interfering with SELECT statements. 
    SET NOCOUNT ON; 

    DECLARE @Month AS INT 
        , @Year AS INT 
    SELECT TOP 1 @Year = DATEPART(YEAR, Date), @Month = DATEPART(MONTH, Date) 
      FROM dbo.JourneyLandingTable 

    SELECT TOP 1 * 
      FROM dbo.JourneyMasterTable 
      WHERE DATEPART(YEAR, Date) = @Year 
      AND DATEPART(MONTH, Date) = @Month 
    IF @@ROWCOUNT > 0 
    BEGIN 
      RAISERROR('JourneyMasterTable already contains data for this month.', 16, 1) 
      RETURN 10 --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
    END 

    SELECT DATEPART(YEAR, Date) AS year1, DATEPART(MONTH, Date) AS month1 
    FROM dbo.JourneyLandingTable 
    GROUP BY DATEPART(YEAR, Date), DATEPART(MONTH, Date) 

    IF @@ROWCOUNT > 1 
    BEGIN 
      RAISERROR('JourneyLandingTable contains data for more than 1 month.', 16, 1) 
      RETURN 20 --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
    END 
END 

vous devriez être en mesure de dire si ce bloc de code a été frappé en vérifiant la valeur de retour de la procédure.