locked
How to let Execute Process Task recognize errors? RRS feed

  • Question

  • Hi there,

    I have a DOS file which runs ok in command line environment. It reads in a text file and does something there then saves it. I cset up error message to outpu if no text file is found. It works ok in DOS but not giving error in Execute Process task. Even it  cannot find text file it still goes through the task. How can I make the task recognize the error? Thanks.

     


    allan
    Wednesday, December 28, 2011 7:58 PM

Answers

  • Yes you can return any non zero value from catch

    You would need to return a error code success from your try block as well something like, which would mean the value 0 is returned from succussfull execution

     

     
    static int Main(string [] args)

    {


    try
    {//Your COde

    return 0

    }

    catch(Exception  ex)
    {
     
    return 213123;
    }

     

     
    //or somehtng like
     
    static int Main(string [] args)

    {

    try{}


    catch{return -1}

    return 0

    }
     


    • Edited by AB82 Friday, December 30, 2011 9:21 AM
    • Marked as answer by allan8964 Friday, December 30, 2011 4:54 PM
    Friday, December 30, 2011 4:56 AM

All replies

  • Hi Allan,

    This is by design because you only ask SSIS to start a process, if it can - it succeeded.

    The trick with DOS is to specify the /C switch; see this thread for more details: http://social.msdn.microsoft.com/forums/en-US/sqlintegrationservices/thread/22229629-3f44-4fb7-afe0-dee53960ee8b/

    I also remember tackling it using StandardErrorVariable, but not sure if you need it.


    Arthur My Blog
    Wednesday, December 28, 2011 8:13 PM
  • Thanks Arthur. I tried the code with /c ... it works. But  my problem is if it's not working it never returns an error! And how shall I set up a variable to the error which is produced by my DOS file?
    allan
    Wednesday, December 28, 2011 9:38 PM
  • Was not sure what your error looks like.

    See if this thread sheds some light: http://social.msdn.microsoft.com/Forums/en/sqlintegrationservices/thread/8df1c8e0-5149-44bd-a6cd-0c7f1364a7cc

    In general it is better to use WMI or PowerShell for this kind of tasks.


    Arthur My Blog
    Thursday, December 29, 2011 3:00 AM
  • Thanks Arthur. That article had same scenario as mine but the poor guy did not get the answer ... although he was grateful. The problem is my console app works in command line, output error message but how can I get that message saved in somewhere as another text file?

    Anyway thank you for your info.

     


    allan
    Thursday, December 29, 2011 4:59 AM
  • The problem is that once you get an exception in your console app,  you are handling the excpetion  and have a catch, as a result a success is returned, i have tried the same, now from my exception code i return a non 0 integer,

    ON the SSIS side on the execute process task there is a property "FailTaskifReturncodeisnot sucess" set it to TRUE, anything retunred from console app which is not 0 will be treated as failure see below the catch code on mine i am explicitly retunring a non 0 integer, also for this change you have to make the return type of your MAIN as int ex:

    Have tested this and this works for me. let me know if you need futher clariifcations 

    catch (Exception ex)

    {

    Console.WriteLine("Failure");

     

    Console.ReadLine();

     

    return 213123;

     

    //Console.WriteLine(ex.Message.ToString() + ex.InnerException.Message.ToString() + ex.Source.ToString());

    }

     

    static int Main(string

    [] args)

    Abhinav
    Thursday, December 29, 2011 5:33 AM
  • Thanks Abhinav. Your explanantion makes sense! I tried to modify the codes with your patern, I changed staic void to static int and added the return -1; at the end (any non-zero should be ok, right?) but I got error "not all code paths return a value" when I tried to compile it. Any guide? Thanks again.

     


    allan
    Thursday, December 29, 2011 8:05 PM
  • Yes you can return any non zero value from catch

    You would need to return a error code success from your try block as well something like, which would mean the value 0 is returned from succussfull execution

     

     
    static int Main(string [] args)

    {


    try
    {//Your COde

    return 0

    }

    catch(Exception  ex)
    {
     
    return 213123;
    }

     

     
    //or somehtng like
     
    static int Main(string [] args)

    {

    try{}


    catch{return -1}

    return 0

    }
     


    • Edited by AB82 Friday, December 30, 2011 9:21 AM
    • Marked as answer by allan8964 Friday, December 30, 2011 4:54 PM
    Friday, December 30, 2011 4:56 AM
  • AB82, You're so right! I added the return statement to all the blocks then recompiled it, it works!!! And now I put it in Execute Process task, it turned red when error occurs. More than that I set the app to return different numbers then I can know the reason for the errors.

    Thank you so much!!!
    Happy New Year!

     


    allan
    • Edited by allan8964 Friday, December 30, 2011 4:55 PM
    Friday, December 30, 2011 4:39 PM