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