If we want to execute SSIS package through c#, Microsoft provides us with an easy to use API.
Here is what we had to be done.
For getting a list of packages that are present on the server.
- Add a reference to your project of Microsoft.SqlServer.Dts.Runtime.
- To get a list of packages that are present on the server use this snippet -
Microsoft.SqlServer.Dts.Runtime.Application app =
new Microsoft.SqlServer.Dts.Runtime.Application();
string serverIp = “YourServerIP”;
PackageInfos pInfos =
app.GetPackageInfos("\\", serverIp, null, null);
foreach (PackageInfo packageInfo in pInfos)
{
if (packageInfo.Flags != DTSPackageInfoFlags.Folder)
cbPackages.Items.Add(packageInfo.Name);
}
- the packageInfo.Flags checks whether the package we are getting is a Folder or a Package
- For Executing the Packages -
string serverIp = "YourServerIp";
foreach (var packageName in cbPackages.Items)
{
Microsoft.SqlServer.Dts.Runtime.Application app =
new Microsoft.SqlServer.Dts.Runtime.Application();
Package package =
app.LoadFromSqlServer("\\" + packageName, serverIp, null, null, null);
DTSExecResult result = package.Execute();
MessageBox.Show(result.ToString());
}
Hope this Helps!!
Happy Programming!!!
Cheers!!!