x
login about faq Site discussion (meta-askssc)

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 '12 at 03:26 AM in Default

pvsrinivasrao gravatar image

pvsrinivasrao
174 21 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

more ▼

answered Jan 16 '12 at 03:49 AM

Amardeep gravatar image

Amardeep
1.3k 71 82 86

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 '12 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 '12 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.

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



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x454
x62
x18
x13

asked: Jan 16 '12 at 03:26 AM

Seen: 1487 times

Last Updated: Jan 16 '12 at 03:26 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.