通過VS.NET調用 SQL 的DTS

來源:互聯網
上載者:User

Method1:

直接訪問 Server

string packageName = "Z_Test1";
   object pVarPersistStgOfHost = null;

   DTS.PackageClass package = new DTS.PackageClass();
   package.LoadFromSQLServer("YourServerName","UserName","Password", 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");
    Console.ReadLine();
          
   }
   catch (Exception ex)
   {
    Console.WriteLine(ex.Message);
   }

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

Method2:

通過打包DTS為 .dts檔案來調用

try
   {
    DTS.Package2Class package = new DTS.Package2Class();
   
    string filename = @"c:\test1.dts";
    string password = null;
    string packageID = null;
    string versionID = null;
    string packageName = "DTSTestPackage";
    object pVarPersistStfOfHost = null;
   
    package.LoadFromStorageFile(
     filename,
     password,
     packageID,
     versionID,
     name, ref
     pVarPersistStfOfHost);
   
    package.Execute();
    package.UnInitialize();
   
    package = null;
   }
   catch(System.Runtime.InteropServices.COMException e)
   {
    Console.WriteLine(e);
   }
   catch(System.Exception e)
   {
    Console.WriteLine(e);
   }

以上,Method1已經通過測試OK,Method2測試總是有問題。

雖然可以調用DTS很方便,但是如果我們把多個DTS整合到一個Jobs裏以後,可以使用SQL Server的排程讓DTS自己運行。這樣的話就會更方便,不需要使用Method1來使用循環來調用DTS,而只需要調用一個Jobs就OK。

但是本人還沒有找到  C#來調用 Sql Jobs的資料,望有資料的朋友能夠提供,謝謝。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.