C # calls the SSIS package and reads the DataReader target

Source: Internet
Author: User
Tags ssis

C # calls an SSIS package that requires reference to two DLLs. (Specific location in the C-drive search, MSDN and Baidu provide the path are not quite correct)

Microsoft.SQLServer.ManagedDTS.dll

Microsoft.SqlServer.Dts.DtsClient.dll

This is an example on MSDN https://msdn.microsoft.com/zh-cn/library/ms136025%28v=sql.120%29.aspx

The example on MSDN only reads a DataReader, and the method cannot add events.

Here is the code that reads multiple DataReader

stringPkglocation =@"package1.dtsx";//Package Pathdtsconnection dtsconnection;          Dtscommand Dtscommand; IDataReader Dtsdatareader=NULL;          Package pkg;          Application app; DataSet DS=NewDataSet (); App=Newapplication (); Pkg= App. Loadpackage (Pkglocation,NULL); stringDatareadername ="datareaderdest"; DtsConnection=Newdtsconnection (); {dtsconnection.m_pkg=Pkg;//dtsconnection.connectionstring = string. Format (@ "/file" "{0}" "", pkglocation); //another way to connect. If you use the package, you can add events//Dtsconnection.open ();} Dtscommand=NewDtscommand (dtsconnection); Dtscommand.commandtext=Datareadername; List<string> reader =Newlist<string> () {"datareaderdest","DataReaderDest2"};//DataReader output Name CollectionList<IDataReader> readers =NewList<idatareader>(); foreach(varCmdtextinchreader) {Dtscommand.commandtext=Cmdtext; Dtsdatareader=Dtscommand.executereader (Commandbehavior.singleresult); Readers.              ADD (Dtsdatareader); Console.WriteLine ("Read {0}", Cmdtext); }          foreach(varDataReaderinchreaders) {              Try{DataTable dt=NewDataTable (); Dt.                  Load (DataReader); Console.WriteLine ("data row {0}", dt.                  Rows.Count); Ds.              Tables.add (DT); }              Catch(Exception ex) {Console.WriteLine (ex).              Message); }              finally{datareader.close ();          }} dtscommand.dispose (); returnds

The above code can read more than 1 DataReader but after reading the first one needs to wait 30 seconds to read the second one, which will be stuck in the code below

Dtsdatareader = Dtscommand.executereader (Commandbehavior.singleresult);

The reason is that the readtimeout of DataReader in the package is set to 30000 milliseconds for 100 milliseconds by default. Each of the DataReader to be set.

C # calls the SSIS package and reads the DataReader target

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.