I have similar code for vb and .net which runs my SSIS package just fine. The problem is the c# code and .net does not run my .dtsx package. I get all sorts of errors in cluding not being able to find the file on my desktop. I tried remotely running the package and locally. Is it my code. I am not sure what to do next.
I do have all the correct references.
// public class clsSSIS1
// {
// public static void RunDTSX()
// {
// string pkgLocation;
// pkgLocation = "C:\\Documents and Settings\\otmxm1\\Desktop\\LoadBeaPayroll\\LoadBeaPayroll\\bin\\package.dtsx";
// Application app = new Application();
// Package package = null;
// Package pkg = app.LoadPackage(pkgLocation, null,true);
//Package pkg = app.LoadPackage(#"C:\Documents and Settings\otmxm1\Desktop\LoadBeaPayroll\LoadBeaPayroll\bin\package.dtsx", null);
// DTSExecResult result = package.Execute();
//Console.WriteLine (result.ToString);
// Console.ReadKey();
// }
// }
// }
Here is a good example I found:
Start the Visual Studio development environment, and create a new application in your preferred development language. This example uses a console application; however you can also run a package from a Windows Forms application, an ASP.NET Web form or Web service, or a Windows service.
On the Project menu, click Add Reference and add a reference to Microsoft.SqlServer.ManagedDTS.dll. Click OK.
Use the Visual Basic Imports statement or the C# using statement to import the Microsoft.SqlServer.Dts.Runtime namespace.
Add the following code in the main routine. The completed console application should look like the following example.
string pkgLocation;
Package pkg;
Application app;
DTSExecResult pkgResults;
pkgLocation =
#"C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services" +
#"\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx";
app = new Application();
pkg = app.LoadPackage(pkgLocation, null);
pkgResults = pkg.Execute();
Console.WriteLine(pkgResults.ToString());
Source: http://msdn.microsoft.com/en-us/library/ms136090.aspx
Why not just execute the
dtexec.exe -f package.dtsx /conf ConfigurationIfYouGotOne
using System.Diagnostics.Process.Start(xxx)?
Or if the the SSIS is deployed to a SQL Server, you can execute it with a stored procedure.
Related
I am using C# to execute a package on a remote server. I am able to successfully execute the package from my staging environment but when i push this code to production I am getting the following DTSError "The executable is not specified.\r\n"
The file locations have not changed and again the package executes from my staging environment. I do not understand why this works in one environment and not the other when they are essentially calling the same SSIS package. Can anyone help me figure out why this error is being thrown? I added my c# code below:
protected void btnsubmit_Click(object sender, EventArgs e)
{
string pkgLocation;
Package pkg;
Application app;
DTSExecResult pkgResults;
pkgLocation = #"\\Someserver\C$\Some_Folder_\Another_folder\Somepackage.dtsx";
app = new Application();
pkg = app.LoadPackage(pkgLocation, null);
pkgResults = pkg.Execute();
Console.WriteLine(pkgResults.ToString());
//Console.ReadKey();
foreach ( Microsoft.SqlServer.Dts.Runtime.DtsError DtsError in pkg.Errors)
{
Console.WriteLine(DtsError.Description);
this.LblDetailResult.Text = DtsError.Description;
}
I have a C# web form built in Visual Studio that calls a SSIS package. The first step in the SSIS package is a Script Tasks that unzips a file. It then deletes data in some tables in SQL Server and then inserts data back into those tables from the contents of the .zip file. When the package is run in VS, it completes successfully without any issues. When I call the package from the C# form, it will not run the Script Task but doesn't throw any errors.
Here is my code that calls the SSIS package:
using System;
using Microsoft.SqlServer.Dts.Runtime; // SSIS Package Execution
namespace LoadZip
{
public class ExecuteSSIS
{
public void exePackage(string tbFilePath, string server)
{
String pkgLocation = #"C:\SSIS.dtsx";
Package ssisPackage;
Application app;
DTSExecResult result;
Variables vars;
app = new Application();
ssisPackage = app.LoadPackage(pkgLocation,null);
vars = ssisPackage.Variables;
vars["sqlServerName"].Value = server; Console.WriteLine("var server = " + server);
vars["filenameWithPath"].Value = tbFilePath; Console.WriteLine("var tbFilePath = " + tbFilePath);
result = ssisPackage.Execute();
if (result == DTSExecResult.Success)
Console.WriteLine("SSIS Package Successfully Executed");
else if (result == DTSExecResult.Failure)
{
Console.WriteLine("********** SSIS PACKAGE FAILED **********");
foreach (DtsError local_DtsError in ssisPackage.Errors)
{
Console.WriteLine(local_DtsError.Description);
}
Console.WriteLine("********** END FAILED REPORT **********");
}
}
}
}
Here is what the SSIS package looks like:
As I mentioned, when I run the package from my C# form, I get returned "SSIS Package Successfully Executed" but it really does not run it. Instead it seems to "fail" at the Script Task and not execute the rest of the package.
If I disable the Script Task (UnZip File) and re-run the SSIS package from my C# form, the package executes successfully. So I know my form is hitting the package and passing along the variables, but it just doesn't seem to like the script task although when executed outside the form, it works just fine.
I'm loading a ssis package from my application which works fine. However, what I'm trying to work out and failing miserably is that the package executes in 1 second (which is great) but the loading of the package takes 9 seconds.
Working locally in visual studio 2015 connecting remotely to a SQL Server 2014 instance.
The package is being loaded in a business object behind an async web api call from a console application.
Heres the code (standard stuff)...
Application application = new Application();
DTSExecResult result;
DTSPackageEventListener eventListener = new DTSPackageEventListener();
packageLocation = request.packageLocation;
//using (Package package = application.LoadPackage(packageLocation, eventListener)) // 9 seconds to load
using (Package package = application.LoadFromDtsServer(#"File System\<PACKAGENAME>", #"<SERVERNAME>", eventListener)) // 9 seconds to load
{
.
.
.
Does anyone have any tips? Any help/guidance would be much appreciated.
Simon.
This is normal, dtsx file is an xml file and the DtsRuntime library need to deserialize the file to load it as dot net class. Also there are some validation that are done on package loading.
Is it possible to log the events of ssis package execution called from c#
Application app = new Application();
Package package = app.LoadPackage("<package_path>", null);
package.ImportConfigurationFile("<configuration_path>");
DTSExecResult result = package.Execute();
I need to log the messages generated during the package execution. I am using SQL Server 2008.
Thanks in advance
the Execute method has an overload for "Log"
log
Type: Microsoft.SqlServer.Dts.Runtime.IDTSLogging
An IDTSLogging interface.
http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.dts.runtime.dtscontainer.execute.aspx
I have scheduled sql agent task which runs an SSIS package. I want to be able to run the SSIS package from .net. Is there a way to either run the SSIS package directly or at least run the SQL agent task which would in turn run the SSIS package.
If it helps it is for a .net 3.5 web app written in C#
Thanks!
The options that are available to run a SSIS package are -
Run package programmatically using SSIS Object Model. This is discussed in details in Books Online here.
An Example:
using System;
using Microsoft.SqlServer.Dts.Runtime;
namespace RunFromClientAppCS
{
class Program
{
static void Main(string[] args)
{
string pkgLocation;
Package pkg;
Application app;
DTSExecResult pkgResults;
pkgLocation = "<package path>\CalculatedColumns.dtsx";
app = new Application();
pkg = app.LoadPackage(pkgLocation, null);
pkgResults = pkg.Execute();
Console.WriteLine(pkgResults.ToString());
Console.ReadKey();
}
}
}
Start DTEXEC.EXE process. DTEXEC is command line utility for executing SSIS packages. See its command line options here.
Use SQL Agent. You can configure an Agent job to run your package (either do it manually in advance if the package is static, or programmatically using SMO or using SQL stored procedures just before running the package), and then start it programmatically using SMO or sp_start_job.
Use some other utility to start DTEXEC for you.
Create a custom application that will run the package (either using OM as described in method #1, or using DTEXEC as in method #2). Expose it as a web service or DCOM class, call this service from your program.
Invent your own :)
Reference: Running SSIS Package Programmatically
Yes. Look into Microsoft.SqlServer.Dts.Runtime namespace. The Package class will provide the methods to run it.