Hello,
I am trying to figure out the code in c sharp to execute an ssis package. I have code for a console application that will run as shown below. But I am looking for code that will execute a Windows Form Application Button.
Ex.
Click a button on a windows forms app and it will execute a specified package.
This is the console application for executing a package from a specified directory.
***************************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
namespace ExecPkg
{
class Program
{
static void Main(string[] args)
{
string pkgLocation;
Package pkg;
Application app;
DTSExecResult pkgResults;
pkgLocation = @"C:\TestPackage.dtsx";
app = new Application();
pkg = app.LoadPackage(pkgLocation, null);
pkgResults = pkg.Execute();
Console.WriteLine("Package has been successfully executed.\n\n" + "Package Results [" + pkgResults.ToString() + "]\n\nGoodbye!");
}
}
}
How do I convert this to windows form application code????
Please help ASAP.
Thank you.
Loading
F DPosted Dec 20, 2011, 12:12 PM
Unfortunately, the code did not work for me. I was able to figure it out eventually, but your input got me in the right direction.
Thanks.
Pravin MorePosted Dec 15, 2011, 2:10 AM
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.SqlServer.Server;
using Microsoft.SqlServer.Dts.Runtime;
private void button2_Click(object sender, EventArgs e)
{
try
{
Application app = new Application();
Package package = null;
package = app.LoadPackage(@"C:\TestPackage.dtsx, null);
//Excute Package
Microsoft.SqlServer.Dts.Runtime.DTSExecResult results = package.Execute();
if (results == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure)
{
foreach (Microsoft.SqlServer.Dts.Runtime.DtsError local_DtsError in package.Errors)
{
MessageBox.Show(al_DtsError.Description.ToString());
}
}
else
MessageBox.Show(results.ToString());
}
catch (DtsException ex)
{
Exception = ex.Message;
}
}
Thanks,
Pravin.