Link to home
Start Free TrialLog in
Avatar of blossompark
blossomparkFlag for Ireland

asked on

Forcing outcome of “ failed” SSIS package to log as “Succcess” in SQL SERVER 2008 Job Log File Viewer

Hi,
I have a SQL Server Agent  job that calls an SSIS package.
The first task of the SSIS package is a C# script that checks for the existence of a file in a folder.
User generated imageThe file may or may not exist in the folder.
If the file exists the task completes successfully and the next task in the package is invoked.
The job retries a number of times before terminating.

The issue I have is that if the file does not exist , when the job finishes it writes an entry in the History  Log that the “Job Failed”.
The job is scheduled to run every day, but the file will appear only once a month, and which day that happens is unknown.
So I end up with a History Log with job fail entries every day except once a month.

As far as I am concerned , the job is a success if it runs, if no file exists, that is not a failure in this context.
So I do not want a job failure written to the History Log of the job.
I still want the job the  package to terminate at the first task if a file is not found, but I do not want fail to be written to the History Log of the Job.
I have included the c# script.
Is there some amendment to this script I can make to achieve this?
Or is there some other way?
I have checked out  the recommendations at these locations below but without success.
http://sqlblog.com/blogs/rushabh_mehta/archive/2008/04/24/gracefully-handing-task-error-in-ssis-package.aspx
http://dougbert.com/blog/post/Faking-success-in-SSIS.aspx

Any guidance appreciated
detect-file-presense-script.txt
SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of blossompark

ASKER

Hi Jim,
Thanks for your comment,
I will  try this and update with results,
Thank you
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Jim Horn and Kevin Cross,
Thanks for your comments.
I have run into  issues with  creating the environment to test  these ideas, the  issue is with my very simple C# script.
I have posted a new question regarding this named;
Simple C# script in SQL Server 2008 SSIS Package not writing to Variable

I would appreciate if  you could have a look at this,,,
Thank you
Hi,
just  to let you know that ;

Simple C# script in SQL Server 2008 SSIS Package not writing to Variable
is now resolved,
Hi,

I have created a variable in the script, if the file is found  a 1 is written to the variable, if not  a 0 is written.
public void Main()
        {
            // TODO: Add your code here
                 String[] DEPOSFiles = Directory.GetFiles(Dts.Variables["User::DirectoryPath"].Value.ToString());
        
             // String Filepath = Dts.Variables["User::DirectoryPath"].Value.ToString() + Dts.Variables["User::FileName"].Value.ToString();
              if (
                  // File.Exists(Filepath))
                   (DEPOSFiles.Length != 0))
              {
                  Dts.Variables["User::FileExistsFlg"].Value = 1;
              }
              else
              {
                  Dts.Variables["User::FileExistsFlg"].Value = 0;
              }
            String FileExistsFlag = Dts.Variables["User::FileExistsFlg"].Value.ToString();
            //MessageBox.Show(Filepath);//Show the folder path with file name
            //MessageBox.Show(FileExistsFlag);//show the flag value, 1 for exists and 0 for not exists
           Dts.TaskResult = (int)ScriptResults.Success;  
        }
          
        }
    }

Open in new window

I have  created an expression and  precedence constraint
User generated image
Th job now writes Success to the History Log  whether or not a file exists.
User generated image
But  what I want is for the job to continue to retry to see if a file exists, and only terminate when the number of retries  have been attempted.
With the current situation, because  I guess, it reads  success every time, it is not attempting retries...
Any ideas on how I can incorporate the retries  and then write Success to the Log even if no file is found with all the retries?
User generated image
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Kevin,
Yes,that is an option,
I am currently trying to code it into the c# script,
the other area i will look into is a for each loop container
Yes, I see what you mean Jim...effectively, the job would be running continuously..
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
currently it is scheduled to retry 48 times with a retry interval of 5 minutes...
re the files....i am told it can land anytime , once a month, monday to friday inclusive,,,,the job to check for this file kicks off at 2am
"48 times with a retry interval of 5 minutes" is a minimum of 4 hours, which seems a long time to repeat.  What is the interval between the job schedules?  How long does the job take to run if the file is found (i.e., finish the other processing)?
Hi Jim and Kevin, thanks for all your help on this... what I've decided to do here is now that I have it writing Success to the Log whether or not a file is present, is  to reschedule the job every 5 minutes,  as Jim says,
If no files, it executes and returns success, no big deal.
If files, it executes and processes the files.

They're will be a lot of "Success" entries in the Log instead of Fails and that was what I was asked to do....
Thanks a million guys....I learnt a lot on this with your assistance,,,,greatly appreciated!! :-)
Thanks for the split.  Good luck with your project.  -Jim
I thought Jim deserved all the credit here, but I too appreciate the split.  I enjoy dialog with folks like you and him as I learn different business uses of SQL tools as well as different perspectives on solutions as tend to think more like a developer than an administrator.  Often there are ways to program around anything, but with the correct architecture and sufficient programming it may be unnecessary to find solutions to everything as you found here.

Good luck!

Best regards and happy coding,

Kevin