3

I have the following code which seems to works OK for executing an SSIS package from c# BUT every time the variable "Resp" returns a Failure even if the package passes when I execute it directly in SSIS.

Again, the package contains a Script component that writes to an SQL server table. All that works OK when the package is executed directly in SSIS but nothing happens when the same package is called via C# with the code below. I cant work out what I am doing wrong. help!

string packageLocation = @"c:\packageLocationPath";
Package pkg;
Application app;
app = new Application();
pkg = app.LoadPackage(packageLocation, null);
var Resp = pkg.Execute();
Hadi
  • 36,233
  • 13
  • 65
  • 124
ibexy
  • 609
  • 3
  • 16
  • 34

1 Answers1

2

Detecting error

First you have to read the errors raised by the package. There are two options to detect these errors:

(1) loop over errors

You can loop over the package errors by accessing Errors property. As example:

if(p.Errors.Count > 0){
    foreach(DtsError err in p.Errors){
        Messagebox.Show(err.Description);
    }
}

More information at:

(2) Enable logging from package

You can capture all errors, warning and information from a package by enabling logging option:


Possible failure causes

  1. Make sure that if you are using windows authentication to connect to SQL, that the user account used to execute the application via C# is granted to make a connection.
  2. If the package is accessing a file system, make sure that the user has the required permissions to access these files
Hadi
  • 36,233
  • 13
  • 65
  • 124
  • 1
    Thank you so much for pointing me in the right direction. By applying the code in your answer I was able to see there were connection issues with one of the sources. Code could not find the connection manager! Its a bit baffling though how the same issues do not prevent the running of the package when executed directly in ssis. I will mark yours as the accepted solution! – ibexy Feb 12 '20 at 03:53