Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to execute package SSIS using c#

Tags:

c#

ssis

I created SSIS package using integration service project in vs 2015. My connection establishment is successful using Datasource. I can execute package using Execute Package Utility and Command line which is successful. Please check below screens shots for the same. Execute package successfully I am facing problem while executing same package using c#. getting failed to execute package. I have applied eventlistener, getting below error. Please find below few screenshots for more information. Error on execute using c# code

Code for reference:

Application app = new Application();
Package pkg = app.LoadPackage(@"C:\Project\Sample\Package1.dtsx", listener);
DTSExecResult results = pkg.Execute(null, null, listener, null, null);

In results object i got failure with given error.

like image 316
Pratik Avatar asked May 14 '26 05:05

Pratik


1 Answers

As @Tab Alleman says you can run the package by calling a stored procedure sp_start_job from C# that starts SQL Agent JOB.

Here a piece of code that can be of help in this type of approach, after creating the SQL Agent JOB:

SqlConnection Conn = new SqlConnection(YOURCONNECTION);

SqlCommand ExecuteJob = new SqlCommand();
ExecuteJob.CommandType = CommandType.StoredProcedure;
ExecuteJob.CommandText = "msdb.dbo.sp_start_job";
ExecuteJob.Parameters.AddWithValue("@job_name", YOURJOBNAME")
ExecuteJob.Connection = Conn; 

using (Conn)
{
    Conn.Open();

    using (ExecuteJob)
    {
        ExecuteJob.ExecuteNonQuery();
    }
}

I hope this help.

like image 111
ɐlǝx Avatar answered May 16 '26 18:05

ɐlǝx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!