How to Execute an Ssis Package from .Net

Run SSIS in .Net 5 Application

As of current version of SSIS, SQL Server 2019, it is a .NET Framework based solution. Script Tasks target 4.5 as a default so take that as an indicator of how far from current Framework, SSIS is based. I don't believe you're going to be able to use the SSIS object model to control package execution.

The other thing to be aware of, even if you manage to get this to work you're likely going to run into legal issues. Running an SSIS package outside of Visual Studio requires a SQL Server license installed on the machine that is running an SSIS package. Period, full stop, do not pass go, do not collect $200. So if your application does this cool stuff as well as runs SSIS packages, the app consumers need to be ready for a licensing fee of 10-20k per core on the machine that runs it, minimum of 4 cores.

Otherwise, you're going to run into an error like

To run a SSIS package outside of SQL Server Data Tools you must install Standard edition of Integration Services or higher

or the error specifies a component isn't installed.

So, assuming you have licensing squared away and no one else has a better idea of how to make the .Net Core manipulate .Net Framework code - how else can you run a package?

DTEXEC

When you install "SQL Server Integration Services" Service, which is on the SQL Server install media, there is an option for the SSIS Service. This gets you through the licensing check and also installs dtexec.exe in the 32 and 64 bit application paths. Running a package deployment model package becomes dtexec /f path/to/my/package.dtsx

Knowing that, it looks like Core supports System.Diagnostics.Process so you're looking at a call like Process.Start("dtexec.exe"); after setting all the parameters https://stackoverflow.com/a/181857

SSISDB

Create your packages using the Project Deployment Model and deploy to a licensed SQL Server machine and the hard stuff goes away. All your application has to worry about is making a connection to SQL Server and then asking SQL Server to run the package.

execute ssis package in MVC

I created a stored procedure which runs the SSIS package. Within MVC it calls the stored procedure -

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Index()
{
//code that updates DB

#region Run Stored Procedure
//connect to the SQL server
var connection = new SqlConnection(_configuration.GetConnectionString("DatabaseConnection"));
//command that runs procedure on the SQL server
var command = new SqlCommand("RebuildSelection", connection)
{
CommandType = CommandType.StoredProcedure,
CommandText = "RebuildSelection"
};
//get text from stored procedure to show success/error messages
SqlParameter text = new SqlParameter("@Text", SqlDbType.NVarChar, 1000)
{
//output as its displayed to the user
Direction = ParameterDirection.Output
};
//add the params
command.Parameters.Add(text);
connection.Open();
//run query
command.ExecuteNonQuery();
//used to return success/error messages to user
ViewData["Message"] = text.Value;
connection.Close();
#endregion

return View();
}

This link was a big help for creating the procedure.

This one helped in returning message to the user.

Running Integration services SSIS on .net core 3.0

You can use different approaches to execute SSIS packages from C# .net core:

Using Transact-SQL command

Instead of using Microsoft.SqlServer.SqlManagementObjects you can simply use an SQLCommand to execute SSIS packages, as example:

Declare @execution_id bigint
EXEC [SSISDB].[catalog].[create_execution] @package_name=N'Package.dtsx',
@execution_id=@execution_id OUTPUT,
@folder_name=N'Deployed Projects',
@project_name=N'Integration Services Project1',
@use32bitruntime=False,
@reference_id=Null
EXEC [SSISDB].[catalog].[start_execution] @execution_id
GO

You can refer to the following links for more information:

  • Run an SSIS package from Visual Studio Code with Transact-SQL
  • Deploy an SSIS project from Visual Studio Code with Transact-SQL

Using DTEXEC utility

Another option is to use Process.Start method to execute DTEXEC application, which is installed with SQL Server.As Example:

Process p = new Process();

// Redirect the output stream of the child process.

p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = @"C:\Program Files\Microsoft SQL Server\130\DTS\Binn\DTExec.exe";
p.StartInfo.Arguments = "/ISServer \"\SSISDB\Project1Folder\Integration Services Project1\Package.dtsx\" /Server \"localhost\"";
p.Start();
Debug.WriteLine(p.StandardOutput.ReadToEnd());
p.WaitForExit();

For more information, you can refer to the following links:

  • Run an SSIS package from the command prompt with DTExec.exe
  • dtexec Utility
  • Running SSIS packages outside the Developer tools using DTEXEC.exe without installing the Integration services
  • Kicking SSIS package off using C# program

Can you run an SSIS task from .net?

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

How to Run SSIS package from cmd prompt or powershell and its dependecies

Can someone help me how to execute the SSIS pacakge in command prompt or powershell and what are the components or installation required?

The error message told you

To Run a SSIS Package outside of SQL Server Data tools you must
install Standard edition of Integration Services or higher

Visual Studio only enables development and interactive execution of SSIS package. Running packages from the command prompt requires a licensed installation of SQL Server Integration Services.



Related Topics



Leave a reply



Submit