woensdag 29 december 2010

SSIS : Adding a connectionmanager in C# (Part II)

In my former post about generating a package with C#, i discovered the various properties of a simple SSIS package. In this post i’ll add a connection to a package with C#. The following code is needed for this (don't forget adding this on top of script: using DTS = Microsoft.SqlServer.Dts.Runtime;):

// Create an application
DTS.Application app = new DTS.Application();

// Create a package
DTS.Package pkg = new DTS.Package();

//Setting some properties
pkg.Name = "MyProgrammedSQLTaskPAckage";
//Adding a connection to the package
DTS.ConnectionManager ConnMgr = pkg.Connections.Add("OLEDB");
ConnMgr.ConnectionString = "Provider=SQLOLEDB.1;" +
    "Integrated Security=SSPI;Initial Catalog=AdventureWorksLT2008R2;" +
    "Data Source=(local);";
ConnMgr.Name = "AdventureWorksLT2008R2";
ConnMgr.Description = "SSIS Connection Manager for OLEDB Source AdventureWorksLT2008R2";

app.SaveToXml(String.Format(@"E:\\SSISProgram\\{0}.dtsx", pkg.Name), pkg, null);
Console.WriteLine("Package  {0} created", pkg.Name);

When i compare the XML schema of the generated SSIS package with the generated SSIS package itself, the following relations can be drawn.


Geen opmerkingen:

Een reactie posten