x

How to execute a DTS task programmitcally using C#.

Hi,

I am working on executing DTS programming. I have a following scenario could you please provide suggestions.

         Package2 package = null;
         package.LoadPackage("\\path");
         foreach (Step2 x in pack.package.Steps)
            {
                if (x.TaskName==selectedTaskName)
                {
                    x.Execute();//this line throws Interface not supported exception. "No such interface supported"
                    int s1 ;
                    string s2 ="";
                    string s3 ="";
                    string s4 = "";
                    int s5;
                    string s6 = "";
                    x.GetExecutionErrorInfo(out s1,out s2,out s3,out s4,out s5, out s6);
                    MessageBox.Show(s1.ToString()+s2+s3+s4+s5.ToString()+s6);
                }
}
more ▼

asked Jan 16, 2012 at 03:26 AM in Default

pvsrinivasrao gravatar image

pvsrinivasrao
174 26 27 27

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

Please check sample code to execute DTS task using c#-

// This method will run the DTS Package private static void RunDTSPackage() {
// Name of the package to run string packageName = "AzamSharpDTSTesting"; object pVarPersistStgOfHost = null;

    DTS.PackageClass package = new DTS.PackageClass();
    package.LoadFromSQLServer("localhost","sa","azam123",

DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrustedConnection , null, null, null, packageName, ref pVarPersistStgOfHost);

    try
    {
        // Execute the package
        Console.WriteLine("DTS Package Executing.."); 
        package.Execute();
        Console.WriteLine("DTS Package Completed");

    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }

    finally
    {
        package.UnInitialize();
        package = null;
    }

}

For more information about the topic please visit the link - [http://www.codeguru.com/csharp/.net/net_data/article.php/c19649][1]

[1]: http://www.codeguru.com/csharp/.net/net_data/article.php/c19649
more ▼

answered Jan 16, 2012 at 03:49 AM

Amardeep gravatar image

Amardeep
1.3k 86 88 89

Thank you the code you gave will execute the entire package however i want only a specific Data Flow Task to be executed within the package.

is it possible?
Jan 16, 2012 at 04:35 AM pvsrinivasrao
Depending on your package structure, you could probably remove the unwanted tasks in memory and then execute the resulting one you want to execute.
Jan 16, 2012 at 01:37 PM Pavel Pawlowski
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x473
x66
x21
x20

asked: Jan 16, 2012 at 03:26 AM

Seen: 3097 times

Last Updated: Jan 16, 2012 at 03:26 AM