// 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";
//adding a "Execute SQL task" to the package
DTS.Executable ExeForSQLTask = pkg.Executables.Add("STOCK:SQLTask");
DTS.TaskHost TKHSQLHost = (DTS.TaskHost)ExeForSQLTask;
TKHSQLHost.Name = "This is a programmed SQL Task";
ExecuteSQLTask MySQLTask = (ExecuteSQLTask)TKHSQLHost.InnerObject;
MySQLTask.Connection = "AdventureWorksLT2008R2";
MySQLTask.SqlStatementSource = "SELECT id FROM sysobjects WHERE name = 'sysrowsets'";
MySQLTask.SqlStatementSourceType = SqlStatementSourceType.DirectInput;
MySQLTask.BypassPrepare = false;
app.SaveToXml(String.Format(@"E:\\SSISProgram\\{0}.dtsx", pkg.Name), pkg, null);
Console.WriteLine("Package {0} created", pkg.Name);
pkg.Dispose();
In SSIS the following windows are the result of executing this C# script:
Hennie
Geen opmerkingen:
Een reactie posten