Using system;
Using system. Collections. Generic;
Using system. text;
Using dtsruntime = Microsoft. sqlserver. DTS. runtime;
Using Microsoft. sqlserver. server;
Using system. Data;
Using system. xml;
Using system. xml. XPath;
Namespace ssisrun
{
Class myeventlistener: dtsruntime. defaultevents
{
// Self-referenced custom log Writing Method
Private Static readonly ilog log = logmanager. getlogger (system. reflection. methodbase. getcurrentmethod (). declaringtype );
Public override bool onerror (dtsruntime. dtsobject source, int errorcode, string subcomponent,
String description, string helpfile, int helpcontext, string idofinterfacewitherror)
{
// Record errors in the package for debugging
Log. info ("error code:" + Source + "<br>" + "error component:" + subcomponent + "<br>" + "error description: "+ description +" <br> ");
Return false;
}
}
Public class runssis
{
// Self-referenced custom log Writing Method
Private Static readonly ilog log = logmanager. getlogger (system. reflection. methodbase. getcurrentmethod (). declaringtype );
Public static string exepackage (string pkgsourse, string configsourse)
{
String theresult = "An error occurred while executing the SSIS package! ";
Myeventlistener eventlistener = new myeventlistener ();
Dtsruntime. Application APP = new dtsruntime. Application ();
Dtsruntime. Package PKG = app. loadpackage (pkgsourse, null); // read the package file (dtsx)
// Dtsruntime. Package PKG = app. loadfromsqlserver ("examplepackage", "SERVER_NAME", "sa", "your_password", null); load packages from SQL Server
PKG. importconfigurationfile (configsourse); // read the configuration spare parts of the package (dtsxconfig)
// PKG. Variables ["XXX"]. value = xxx can also assign values to the package variable in this way.
Log. Info ("Starting execution package ");
Dtsruntime. dtsexecresult result = PKG. Execute (null, null, eventlistener, null, null );
Log. Info ("execution package result:" + result );
If (result. Equals (dtsruntime. dtsexecresult. Success ))
{
Theresult = "SSIS package executed successfully! ";
}
Return theresult;
}
}
}