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.
Related
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
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 developed SSIS packages on a PC which has integration services installed.
Then i want to develop a C# winforms application execute these packages on client PC. But the client PC has SQL Server installed without integration services.
So i created a C# application and added the packages to it, and added a reference to Microsoft.SQLServe.ManagedDTS then executed the packages, and the result is that some simple packages get executed successfully but complex ones not executed the give an error
The component metadata for "Script Component, clsid {33D831DE-5DCF-48F0-B431-4D327B9E785D}" could not be upgraded to the newer version of the component. The PerformUpgrade method failed.
The component is missing, not registered, not upgradeable, or missing required interfaces. The contact information for this component is "Includes and runs custom script code. For example, apply a business rule that limits the range of valid values in an "income" column or add values in two columns and calculate the average of the sum.;Microsoft Corporation; Microsoft SQL Server; Microsoft Corporation; All Rights Reserved; http://www.microsoft.com/sql/support;10".
Script Component failed validation and returned error code 0xC0048021.
And when i seached online i found most of the solutions is about if integration services is installed right.
My C# code winform code
private void button1_Click(object sender, EventArgs e)
{
Package prepartion;
Package storeLoad;
Microsoft.SqlServer.Dts.Runtime.Application app;
DTSExecResult pkgResults;
Project project = Project.OpenProject(System.Windows.Forms.Application.StartupPath + #"\SSISLoad.ispac");
project.Parameters["Con1"].Value = sqlServerTextBox.Text;
project.Parameters["Con2"].Value = "Dsn=mysqlconn";
prepartion = project.PackageItems["Preperation.dtsx"].Package;
storeLoad = project.PackageItems["StoreLoad.dtsx"].Package;
pkgResults = prepartion.Execute();
output.Text = pkgResults.ToString();
pkgResults = storeLoad.Execute();
output.Text += "\r\n" + pkgResults.ToString();
foreach (var x in prepartion.Errors)
{
output.Text += "\r\n" + x.Description;
}
foreach (var x in storeLoad.Errors)
{
output.Text += "\r\n" + x.Description;
}
}
So is the problem because integration services is not installed on client PC where my application is running or something else ?
And is there a way to get this done without installing integration services on client PC.
Thanks in advance
Not having Integrated services isn't the cause for this error. It seems when your packages are loading something is trying to upgrade them to whatever sql server version your using. I have seen this before when doing upgrades to more recent versions of SSIS or even sometimes SQL Server.
So I have a solution with two projects (webapi, console app) in it. I created a shared directory between them to put a sqlite database.
So I use
Path.GetFullPath(#"../shared/" + Configuration["DBName"]);
and get this path when i run it in visual studio 2017
\shared\sqlite.db
However when I try to run the console command
dotnet ef database update
it thinks it's located here
\projecta\bin\Debug\shared\
How can I get the Visual Studio debug and dotnet ef commands to use the same path?
When you call Path.GetFullPath, it uses the value of Directory.GetCurrentDirectory, which may vary based on who called your code (VS, dotnet, etc)
A better way to do this is give your SQLite file path a consistent location that won't vary based on the caller:
var dbPath = Path.Combine(System.AppContext.BaseDirectory, "..", "shared", Configuration["DBName"]);
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/