Test Platform: Windows2003 R2 SP2; SQL Server 2005 with all the latest patches; VS 2005 Professional Edition; vs2008.
Earlier versions:
[Technical Documentation] How to Use C # Call SSIS package
The following is an example:
To use a package with parameters, first introduce
Using Microsoft. sqlserver. DTS. runtime;
Then assign values to the package variables in the program. The specific method code is as follows:
Private void runetl ()
{
Console. writeline ("ETL start ...");
String filepath = installedpath + "// ETL // package. dtsx ";
Microsoft. sqlserver. DTS. runtime. Application application = new Microsoft. sqlserver. DTS. runtime. Application ();
Package package = application. loadpackage (filepath, null, true );
Package. Variables ["dbservername"]. value = dwservername;
Package. Variables ["dbname"]. value = dwdbname;
Package. Variables ["varfoldername"]. value = thispath;
Dtsexecresult result = package. Execute ();
If (result. Equals (dtsexecresult. Success ))
Listbox1.items. Add ("ETL success ");
Else
{
Listbox1.items. Add ("ETL failed ");
Return;
}
}
The current environment should be:
Add references first
C:/program files/Microsoft SQL Server/90/SDK/assemblies/Microsoft. sqlserver. dtsruntimewrap. dll 9.0.242.0
After joining, Microsoft. sqlserver. dtsruntimewrap is displayed.
Using dtsruntime = Microsoft. sqlserver. DTS. runtime. wrapper;
This wrapper is available in new versions. For earlier versions, only using dtsruntime = Microsoft. sqlserver. DTS. Runtime is required.
Now we introduce using Microsoft. sqlserver. DTS. runtime. wrapper;String filepath = "t_ship_history_price.dtsx"; Microsoft. sqlserver. DTS. runtime. wrapper. application application = new Microsoft. sqlserver. DTS. runtime. wrapper. application (); <br/> Microsoft. sqlserver. DTS. runtime. wrapper. idtspackage90 package = application. loadpackage (filepath, true, null); <br/> // package. variables ["dbservername"]. value = dwservername; <br/> // package. variables ["dbname"]. value = dwdbname; <br/> // package. variables ["varfoldername"]. value = thispath; <br/> dtsexecresult result = package. execute (); <br/> // package. tolerations ["date"]. configurationstring = "20090214"; <br/> If (result. equals (dtsexecresult. dtser_success) <br/> textbox1.text = "ETL success"; <br/> else <br/>{< br/> textbox1.text = "ETL failed "; <br/> return; <br/>}