question

pvsrinivasrao avatar image
pvsrinivasrao asked

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); } }
sql-server-2000dtsc#programming
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Sharma avatar image
Sharma answered
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
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

pvsrinivasrao avatar image pvsrinivasrao commented ·
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?
0 Likes 0 ·
Pavel Pawlowski avatar image Pavel Pawlowski commented ·
Depending on your package structure, you could probably remove the unwanted tasks in memory and then execute the resulting one you want to execute.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.