I have the following code which seems to works OK for executing an SSIS package from c# BUT every time the variable "Resp" returns a Failure even if the package passes when I execute it directly in SSIS.
Again, the package contains a Script component that writes to an SQL server table. All that works OK when the package is executed directly in SSIS but nothing happens when the same package is called via C# with the code below. I cant work out what I am doing wrong. help!
string packageLocation = #"c:\packageLocationPath";
Package pkg;
Application app;
app = new Application();
pkg = app.LoadPackage(packageLocation, null);
var Resp = pkg.Execute();
Detecting error
First you have to read the errors raised by the package. There are two options to detect these errors:
(1) loop over errors
You can loop over the package errors by accessing Errors property. As example:
if(p.Errors.Count > 0){
foreach(DtsError err in p.Errors){
Messagebox.Show(err.Description);
}
}
More information at:
How to get all errors of all SSIS packages in a solution
(2) Enable logging from package
You can capture all errors, warning and information from a package by enabling logging option:
Add and configure logging
Possible failure causes
Make sure that if you are using windows authentication to connect to SQL, that the user account used to execute the application via C# is granted to make a connection.
If the package is accessing a file system, make sure that the user has the required permissions to access these files
Related
I am trying to edit a SSIS package from code using ManagedDTS dlls (and others) and I need to access one of the connections defined in the package in order to re-map the columns in one of the source components. The problem is that this connection is created with a custom connection manager and it is therefore not recognized, when the package is loaded.
The code should be something like this:
Application app = new Application();
Package package = app.LoadPackage("packagepath", null);
var customConnection = package.Connections["customConnectionManager"];
Where the customConnection is the connection that I am looking for.
I am able to create a new package with this type of connection but as soon the package is saved and reloaded, I don't have access to it.
The custom connection manager is in GAC and can be normally used in VS SSDT. When I make a new package in add the connection "customConnectionManager" is works as intended.
Is there a way to access connections in the SSIS packages that are made with custom connection managers?
Thanks in advance!
I have a C# script that is being called from an SSIS package. This script compresses files in a folderA and saves the compressed file to folderB.
When I run this SSIS package(that calls the C# script) manually from Microsoft Visual Studio, it runs successfully. However, once I deploy this package to the SSIS DB of my database server and create an SQL Server Agent Job and run this job, the package calling the C# script fails.
When I try to check the 'All Executions' report of the running SSIS project, I notice there is an error message saying, Exception has been thrown by the target of an invocation
This error message is not really informative thus, I do not know why this error happens.
Any ideas on why this error occurs or help to further narrow down my investigation?
Thank you very much!
The problem was because the SQL service agent was not granted write permission to the folder where the compressed file should be saved.
Setup
I have a vs2010 SSIS package that I can run from visual studio. I have deployed it to my local 2012 server, and I can also execute that package from SSMS. In SSMS, I see the package here:
\Integration Services Catalogs\SSISDB\DAT_Load\Projects\UploadSYS.dtsx
Note: vs2010 does not give me an option to deploy a package anywhere but in a server, and then only in Integration Services Catalogs. Once in there, the MSDB database does not have an entry in the sysssispackages table.
Previously, it was adequate to bring up SSMS and run the package from there(right-click & execute). Now, I have to execute this from a C# web application. Furthermore, I need to trap progress messages and such through events.
Effort
I was able to determine how to set up the event trapping and I got myself to the point where I should have been able to execute the package from code:
public DTSExecResult ExecutePackage(string packageName, HttpContextBase context)
{
string ppath = ConfigurationManager.AppSettings[packageName + "Package"];
string pserv = ConfigurationManager.AppSettings[packageName + "Server"];
string puser = ConfigurationManager.AppSettings[packageName + "User"];
string ppass = ConfigurationManager.AppSettings[packageName + "Pwd"];
_context = context;
_pkgLocation = "";
_app = new Application();
_pkg = _app.LoadFromSqlServer(ppath, pserv, puser, ppass, _SSISEvents);
_pkgResults = _pkg.Execute(_connections, _variables, _SSISEvents, _log, null);
return _pkgResults;
}
Problem
I cannot locate the package. When I reach the LoadFromSqlServer statement, I receive an error that says:
Cannot find folder "\Integration Services Catalogs\SSISDB\DAT_Load\Projects\UploadSYS.dtsx"
The same thing happens for variations in the path (variable = ppath):
\Integration Services Catalogs\SSISDB\DAT_Load\Projects\UploadSYS.dtsx
\SSISDB\DAT_Load\Projects\UploadSYS.dtsx
\DAT_Load\Projects\UploadSYS.dtsx
etc.
Running this from the command line or a stored procedure is not an option.
So, can anyone tell what I am missing here? Does the Application object need to initialize something? Is this even possible?
Taking another bite at the problem but see Set SSIS database package path and SSIS Organization for background reading.
Until SSIS 2012, if packages were deployed to SQL Server, they lived in the msdb. The .NET API for interacting with them was the same across versions.
With the 2012 release of SSIS, we have two different deployment models. Package deployment, which is the "classic" model is alive and fully supported. The same code for running a package on 2005 will work for 2012 package deployment model projects. This is the Microsoft.SqlServer.Dts.Runtime Namespace
Your code is attempting to load a 2012 solution built using the "project deployment model" with the "package deployment model" API. This is the Microsoft.SqlServer.Management.IntegrationServices Namespace and the two don't mix.
Your options are to switch your project back to the Package deployment model or update your code. In the first linked question, I provided the VB.NET implementation for running an SSIS package in the SSISDB catalog. There is some way of running a .ispac file because I see the option in dtexec but I'm not seeing the specific method. This is mechanism VS/SSDT uses when it runs the packages locally.
By refering msdn website and other community i was able to run my packages programmatically. I am using a console .net application to run my ssis package. i have hardcorded the location package. it runs smoothly
DTSExecResult pkgResults;
Application app = new Application();
Package p = app.LoadPackage(#"C:\somelocation");
pkgResults = p.Execute();
if (pkgResults == DTSExecResult.Success)
Console.WriteLine("Package ran successfully");
else
Console.WriteLine("Package failed");
the problem i am facing is when i fails i am unable to record which ran successfully and which has failed or stopped in between.
is there anyway to log my progress programmatically in C#, should i use custom method or use their inbuild methods like DTS.LogProvider.
is there anyway i could send a email stating the it has succeeded or failed.
This might be helpful.
There is a code snippet also.
http://msdn.microsoft.com/en-us/library/ms136023.aspx
Logging is available in ssis. You can program any number of tasks to execute on a given event, including a 'send mail' task. See this article to configure logging options in ssis
http://msdn.microsoft.com/en-us/library/ms167456.aspx
I have an application where whenever a file is uploaded to a directory, I have to call SSIS to parse the XML file.
Can I call a SSIS directly from a .NET Windows service?
Running SSIS package programmatically.
I prefer the second method:
Start DTEXEC.EXE process. DTEXEC is command line utility for executing SSIS packages. See its command line options here: http://msdn2.microsoft.com/en-us/library/ms162810.aspx
Benefits: running package out of process gains reliability. Can be used from any programming language (including .NET 1.1 :)). Easy to pass parameters by setting variables values.
Drawbacks: Also local only. Harder to get information about package progress (but SSIS logging can give you most functionality). Some overhead on starting new process (likely minimal compared to execution time for big packages).
ASP.NET specific: Win32 CreateProcess function ignores the thread impersonation. So if you want DTEXEC to run under account different from ASP.NET process account, you should either make user enter name/password and pass it to Process.Start, or use method described in the following KB to run child process under impersonated account http://support.microsoft.com/kb/889251.
you can run your SSIS package programmatically, as follow:
using System;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
namespace ConsoleApplicationSSIS
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Loading SSIS Service...");
//Application object allows load your SSIS package
Application app = new Application();
//In order to retrieve the status (success or failure) after running SSIS Package
DTSExecResult result ;
//Specify the location of SSIS package - dtsx file
string SSISPackagePath = #"C:\Microsofts\BI\SSIS\ConsoleApplicationSSIS\IntegrationServiceScriptTask\Package.dtsx";
//Load your package
Package pckg = (Package)app.LoadPackage(SSISPackagePath,true,null);
//Execute the package and retrieve result
result = pckg.Execute();
//Print the status success or failure of your package
Console.WriteLine("{0}", result.ToString());
Console.ReadLine();
}
}
}
if you want a complete sample, go to :http://hassanboutougha.wordpress.com/2012/10/13/run-your-ssis-package-progammatically/
I explain how create a simple SSIS package and after how to call it programmatically from a console application. Don't forget to have this assembly :C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SQLServer.DTSRuntimeWrap.dll to reference runtime ssis namespace
you can also pass your variables programmatically and change also source and destination connections of your ssis package
You can call SSIS programtically, execute the package and change the configuration from a .NET code using DTS runtime. Here is complete code of how you can do it.
You can call the SSIS package from your windows service. But Microsoft.SqlServer.Dts should be installed into the system where windows services are going to run. If you have installed DTS installed in that machine, directly call the SSIS package. If it is not installed then you should do the following.
Create the SSIS package
Create the job which runs the SSIS package
In your ADO.NET[resides in windows services code], Call stored
procedure which runs job[configured to run the SSIS package].
Following is an example should be called from your .NET code.
EXEC msdb.dbo.sp_start_job N'YourJobName'
Hope this helps!
Updating this pretty old question:
On SQL Server 2012 you can do this simply by creating stored procedure that will call to create_execution and set_execution_parameter
Step-by-step guide can be found here: https://blogs.msdn.microsoft.com/biblog/2013/05/07/step-by-step-of-executing-ssis-2012-package-through-stored-procedure/