execute package with .net and Job - ssis

is it possible to execute a Package with both a job and from .net?
how to change the input parameter?

Yes you can execute the SSIS packages using SQL Agent and from a .NET application.
If you need to pass the input parameter then you need to use the SET option while executing through DTEXEC command line
/SET "\Package.Variables[User::YourVariable].Properties[Value]";"ValueToBePassed"
If you have several parameters to pass then you can use the above the query in a text file and then use the CommandFile option in DTEXEC
DTEXEC /File "C:\Package.dtsx" /CommandFile "C:\inputOptions.txt"
If your running from .NET .Add a reference to Microsoft.SqlServer.Dts.Runtime.Application
using app=Microsoft.SqlServer.Dts.Runtime.Application;
string pkgLocation;
Package pkg;
DTSExecResult pkgResults;
pkgLocation = #"C:\SSISPackage\YourPackage.dtsx";
app = new Microsoft.SqlServer.Dts.Runtime.Application();
pkg = app.LoadPackage(pkgLocation, null);
pkg.Variables["VariableName"].Value = "VariableValue";
results= pkg.Execute();
Refer my answer in SO.I have used a script task to execute the package but you can use that code in your .NET app
Refer this article for further information

Related

Load package from SQL Server

I used following article to execute SSIS package parallel.https://www.sqlservercentral.com/articles/importing-files-in-parallel-with-ssis. In this article it explained execute a package from a folder location. In my situation I am deploying both packages. I tried following code:
Application app = new Application();
Package pkg = app.LoadFromSqlServer(dtsxPackage, "localhost",null, null, null);
I am getting error
Cannot find folder "Package name"
Package deployment is as follows.
Using "ParallelExecusion.dtsx" I am try to execute the "FileSync.dtsx" package. I am setting the package path as "FileSync\TeamR\FileSync.dtsx"
The code shown is for loading a package that is stored in the SQL Server database named msdb. It will use the binaries in sys.dtspackages90 or sys.ssispackages (table names approximate) but that only works for packages developed and deployed under the Package Deployment Model (2005-2008R2) or projects that are explicitly defined as such for SQL Server 2012+
What your screenshot shows is a Project Deployment Model which is a .ispac deployed to the SSISDB database. While that package is on SQL Server, you do not use the LoadFromSqlServer method. Instead, you're going to use the same-ish methods that the CLR methods in the database use.
CreateSsisServerExecution
Set any Parameter/Property values
Start
Personally, unless I had a strong use case that I needed to control every aspect of the package execution, I'd just use TSQL here (and remove class dependencies in your code) to Execute SSIS Packages

how to call a deployed ssis 2012 package from execute package task from another ssis package

I have a ssis 2012 package that has been deployed on the server. Now I am creating another ssis package that will call that deployed package through execute package task. Can someone tell me how to achieve this. ?
I tried to do the following things -
tried to find the deployed path so that I can use that path inside execute package task. But I could not find the path in which package is deployed. can my goal be achieved in this way.
Tried to use execute sql task instead of execute package task but this did not work.
Select Project Reference for child packages that are in the project. Select External Reference for child packages that are located outside the package.
Set to External Reference if the project that contains the package has not been converted to the project deployment model.
https://msdn.microsoft.com/en-us/library/hh479606.aspx
If you are trying access package already deployed in SSISDB Catalog through Execute Package Task, then you have to download that project and include your parent package to that project. As end of the day you will be required to deploy your parent package to the same SSISDB catalog (You can not access package of different project through Execute Package task).
To Execute package through Execute SQL Task:
you can script out the TSQL code of your SSISDB deployed package by Right cLick on package>Execute>Script to...
EXEC [SSISDB].[catalog].[create_execution]
#folder_name = N'Folder',
#project_name = N'Test',
#package_name = N'Package.dtsx',
#reference_id = NULL,
#use32bitruntime = FALSE,
#execution_id = #executionID OUTPUT
EXEC [SSISDB].[catalog].[set_execution_parameter_value]
#executionID,
#object_type = 20,
#parameter_name = N'Var1',
#parameter_value = #Var1
EXEC [SSISDB].[catalog].[set_execution_parameter_value]
#executionID,
#object_type = 20,
#parameter_name = N'Var2',
#parameter_value = #Var2
EXEC [SSISDB].[catalog].[start_execution] #executionID

SSIS 2008 Execute Package Task Connection Expression not valid

In SSIS 2008 I am trying to configure a package to execute another package using the Execute Package Task. In the Execute Package Task Connection expression I am using a variable that contains the absolute path to the folder where the package I want to execute is located because as we all now relative paths don't work in SSIS. The expression evaluates to what looks to be the right path as can be seen in the screenshot below.
However when I try to execute the package I get the following error that it can't find the package:
I am very confused by this because the package path is correct. Any ideas?
I think you are setting the connection in the wrong place.
You need to set the connection string in the connection manager.
Example that I want to change the Package1.dtsx to execute Package2t.dtsx ..
Created Connection Manager "Package1.dtsx" that references a package in a folder called Package1.dtsx
Properties of Connection of Package1.dtsx in Connection Manager
Change ConnectionString in Connection Manager to execute Package2t.dtsx.
Try including double quotes since your file path string has spaces in it
"\"" + #[User::RootFolder] + "\\" + "ImportSessionAndSubsessions.dtsx\""

Dynamically set connection string of SSIS package through cmd

I am trying to dynamically set the connection string of my SSIS package through DTEXEC.exe
My CMD file consists of following command.
"C:\Program Files\Microsoft SQL Server\100\DTS\Binn\DTEXEC.exe" /f
"D:\ABC\XYZ\Packages\ABCD.dtsx" /CHECKPOINTING OFF /REPORTING V /CONSOLELOG/Conn
"Configurations;'"Data Source=XXXXXX;Initial Catalog=YYYY;Provider=SQLNCLI10.1;Integrated
Security=SSPI;Auto Translate=False;'"" /SET
"\Package.Variables[User::TargetEnvironmentId].Properties[Value]";"2"
If i take out connection string part it works fine but when i add
/Conn "Configurations;'"Data Source=XXXXXX;Initial Catalog=YYYY;Provider=SQLNCLI10.1;
Integrated Security=SSPI;Auto Translate=False;'""
This it throws exception and says INVALID
Is the name of your connection manager called "Configurations"? I can only assume that is the case. Give the following a try:
/CONNECTION "Configurations";"\"Data Source=XXXX;Initial Catalog=YYYY;Provider=SQLNCLI10.1;Integrated Security=SSPI;Auto Translate=False;\""
I always find it easier to use DTExecUI to create the script, have you tried doing that?
Either that or set the connection string as a variable and pass that through DTExec

Is there a way to run a SSIS package in 32 bit runtime from another project which is built to "Any CPU" output?

I have an SSIS package in which I am reading data from a csv and dumping it to an excel file (.xls). At first, it did not work and I had to change the SSIS project 64-bit runtime property to false to make it work.
I need to call this package from another windows service which is built to "Any CPU" output. When I do so, I get the same 64-bit runtime error and the package fails. I cannot change the runtime of the service to x86/x64. Is there a solution so that I can tell the package that it needs to execute in the 32-bit runtime from the service?
try to set this property to false (its on the solution's properties):
Also, rememebr that Dtexec, dtutil, and the SQL Server Import and Export Wizard have both a 64-bit and a 32-bit application. Be sure to note that if you develop a package in a 32-bit environment and want to run the package in a 64-bit environment, the connection managers need to be 64-bit compliant. Some connection managers such as Excel work in a 32-bit environment only.
It's possible to force 32 bit execution through EXEC Commands:
EXEC SSISDB.catalog.create_execution
#folder_name = #p_yourFolder,
#project_name = #p_yourProject,
#package_name = #p_yourProcess,
#reference_id = #v_yourReferenceId,
#use32bitruntime = 1, --To force 32 bit runtime
#execution_id = #r_SSISDB_ExecutionID OUTPUT;
Or through a SQL Agent in Configuration\Advanced properties where you have a «Run in 32 bit mode» check box available.