Call the package developed by SSIs in C #. NET and use logs to record errors and exceptions in package execution.

Source: Internet
Author: User
Tags ssis

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;

}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.