Showing posts with label disk. Show all posts
Showing posts with label disk. Show all posts

Friday, March 23, 2012

Executing a package from within a C# program returns failure everytime

Hi All,

I am trying to execute a package (programmatically) that is stored on my local disk using the information that is provided on the following page:

http://msdn2.microsoft.com/en-us/library/ms136090.aspx

This means, I am using the Application object and the Package object to actually load the package using the path to it.

So my code looks something like this:

--

pkgLocation = @."<package_path>/Package1.dtsx";

app = new Application();

pkg = app.LoadPackage(pkgLocation, null);

pkgResults = pkg.Execute();

Console.WriteLine(pkgResults.ToString());

Console.ReadKey();

My package reads in a flat file (located on another server) and transforms it and saves it to a database (on that same server). And mind you, I can execute this package just fine when I do it manually from within BIDS.

But when I try to execute the above mentioned code in my C# solution (compiled to a command line executable), I always get a "Failure".

Can somebody point out what I am doing wrong here?

Thank you in advance,

Manan Pancholi

You can use the following code to get the errors after execution

foreach (DtsError dtserr in pkg.Errors)
{
Console.WriteLine("Source: " + dtserr.Source + ", Description: " + dtserr.Description);
}|||

Thanks Kaarthik,

I believe I have narrowed down the problem. It seems that unless the Integration Services are installed on my machine, I would not be able to execute some tasks that are part of the package that I am calling programmatically. Atleast thats what the error information pointed out to me.

I believe that the authentication works differently when I am trying to execute the package manually and when I am trying to execute the package in my C# code. This is kind of odd, but thanks again for the help.

I will follow this up with a detailed example of how to execute a package programmatically and what sort of permissions would one need when working with remote sources and destinations.

Manan Pancholi

Friday, March 9, 2012

Execute SQL Task passing parameters to a restore command

Hi,

I'm very new to SSIS and I’m trying to do the following in a SQL task

RESTORE DATABASE @.DatabaseName FROM DISK = @.Backup WITH FILE = 1, MOVE @.OldMDFName TO @.NewMDFPath, MOVE @.OldLDFName TO @.NewLDFPath, NOUNLOAD, REPLACE, STATS = 10

I'm using an OLE DB connection and I have mapped user variables to the various parameter names. Unfortunately when i test the above command it fails on must declare the scalar variable "@.DatabaseName". How can i get my values to be substituted into the command?

Many thanks

Martin

The best way is to build your SQL statement in a variable via expressions and then use that variable as the SQL source for the Execute SQL task.|||I don't think you can parameterize a RESTORE DATABASE command like that.

The way I'd do it is to create a new parameter named SqlStatement or something of similar meaning. This parameter's EvaluateAsExpression property will be True and the Expression property will be: "RESTORE DATABASE " + @.[User::DatabaseName] + " FROM DISK = ...". Then set the SQLSourceType of your Execute SQL Task to Variable and specify SqlStatement as the variable.