使用C#调用DTS包

学习ing......
在MSDN中的以下章节可以看到具体介绍
ms-help://MS.MSDNQTR.2003FEB.2052/enu_kbsqlserver/en-us/sqlserver/Q319985.htm

调用步骤:
1.在sqlserver中创建DTS包

2.C#代码调用
using System;
using System.Runtime.InteropServices;
using DTS;

namespace DtsInterop
{
 class ExecPkgWithEvents
 {
  public Package2Class package;

  public void Run()
  {
   try
   {
    package = new Package2Class();

    object pVarPersistStgOfHost = null;

    package.LoadFromSQLServer("YOUR_SERVER_NAME", null, null, DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrustedConnection, null,
     null, null, "YOUR_PACKAGE_NAME", ref pVarPersistStgOfHost);

    package.Execute();
    package.UnInitialize();
    package = null;
   }
   catch(System.Runtime.InteropServices.COMException ex)
   {
    Console.WriteLine("COMException {0}\n{1}\n{2}", ex.ErrorCode, ex.Message, ex.StackTrace);
   }
   catch(System.Exception ex)
   {
    Console.WriteLine("Exception\n{0}\n{1}", ex.Message, ex.StackTrace);
   }
  }
 }
}
注:需要引用的COM组件为Microsoft DTSPackage Object Library

以上方法希望对大家能有所帮助!

你可能感兴趣的:(C#)