国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > .NET > 正文

通過(guò)Visual C#.NET建一個(gè)DTS任務(wù)

2024-07-10 13:00:09
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
  • 本文來(lái)源于網(wǎng)頁(yè)設(shè)計(jì)愛(ài)好者web開(kāi)發(fā)社區(qū)http://www.html.org.cn收集整理,歡迎訪問(wèn)。
  • 本文描述了如何利用visual c#.net 創(chuàng)建一個(gè)dts 自定義的任務(wù)。你可以通過(guò)c#.net創(chuàng)建自定義的任務(wù)的方式擴(kuò)展dts的功能。之后你可以安裝并注冊(cè)任務(wù),他講出現(xiàn)在dts設(shè)計(jì)其中,就像默認(rèn)的dts任務(wù)。總之,你能夠使用.net framework創(chuàng)建自定義的任務(wù)。

      在本文中除了講創(chuàng)建一個(gè)dts自定義任務(wù)外,還包括一下部分內(nèi)容:

      1、這篇文章中自定義的代碼分為編譯、注冊(cè)和安裝自定義任務(wù);

       2、這部分一個(gè)有特色的部分就是你可以運(yùn)行自定義的任務(wù);

       3、在開(kāi)發(fā)過(guò)程中你可以使用本文提及的一些工具(除非另有說(shuō)明,這些工具已經(jīng)包含在.net中了,您可以通過(guò).net的命令行運(yùn)行這些工具)。

       為dtsspkg.dll創(chuàng)建一個(gè)及時(shí)的包

      如果一個(gè)基于微軟.net客戶機(jī)訪問(wèn)一個(gè)com組件,你必須使用一個(gè)包(這個(gè)組件包含的)。這類的包是及時(shí)的運(yùn)行包(rcw)并且你也可以通過(guò)開(kāi)放dtspkg.dll的類型庫(kù)編譯。你也可以使用類型庫(kù)導(dǎo)出工具(tlbimp.exe)編譯rcw,如:

    tlbimp.exe “c:/programfiles/microsoft sqlserver/80/tools/binn/dtspkg.dll”/out:microsoft.sqlservver.dtspkg80.dll/keyfile:dtspkg.snk

    “/keyfile”參數(shù)代表microsoft.sqlserver.dtspkg80.dll帶有強(qiáng)類型名用public或private關(guān)鍵字。使用強(qiáng)類型名工具(sn.exe)在dtspkg.snk 前創(chuàng)建關(guān)鍵字:

    sn.exe –k dtspkg.snk

      你應(yīng)該使用一個(gè)強(qiáng)類型名像其他的全局集合緩存,因?yàn)槟惆惭b了運(yùn)行包。

      在全局集合緩存中安裝運(yùn)行包

      用全局集合緩存工具(gacutil.exe)安裝運(yùn)行包:

    gacutil.exe /i microsoft.sqlserver.dtspkg80.dll

     安裝了運(yùn)行包后,你可以像添加.netc#工程中的引用一樣的添加。
      
      為自定義的任務(wù)添加代碼

      代碼的自定義注冊(cè)。.net沒(méi)有開(kāi)放dllreginsterserver 和dllunregisterserver 像com組件的入口,但是你可以使用comregisterfunctionattribute 類執(zhí)行任務(wù)注冊(cè)和撤銷注冊(cè)。在自定義類聲明之前添加下面代碼:

    [guid("a39847f3-5845-4459-a25e-de73a8e3cd48"), comvisible(true)]

    [progid("dts.simpletask")]

    public class simpletask : customtask

    {

    //implementation of custom task

    }

      下面的代碼是一個(gè)函數(shù)注冊(cè)的范例執(zhí)行。函數(shù)的全部代碼在自定義任務(wù)的編譯、注冊(cè)和安裝部分 。

    [system.runtime.interopservices.comregisterfunctionattribute()]

    static void registerserver(type t)

    {

    //code to register custom task

    }

      注冊(cè)函數(shù)增加下面的鍵值用來(lái)注冊(cè)。

    hkey_classes_root/clsid/a39847f3-5845-4459-a25e-de73a8e3cd48/implemented categories/{10020200-eb1c-11cf-ae6e-00aa004a34d5}

    10020200-eb1c-11cf-ae6e-00aa004a34d5是dts包對(duì)象的類編號(hào)。因?yàn)樗械淖远x的任務(wù)執(zhí)行自定義的接口所以必須注冊(cè)。注冊(cè)函數(shù)添加下面的注冊(cè)鍵值:

    hkey_current_user/software/microsoft/microsoft sql server/80/dts/enumeration/tasks/a39847f3-5845-4459-a25e-de73a8e3cd48

      下面的dts任務(wù)緩存目錄列表,使自定義的任務(wù)出現(xiàn)在dts設(shè)計(jì)器中:

    hkey_current_user/software/microsoft/microsoft sql server/80/dts/enumeration/tasks/

      下面的代碼示范非注冊(cè)函數(shù)的任務(wù)移出的執(zhí)行。面注冊(cè)函數(shù)是comunregisterfunctionattribute類在.net運(yùn)行庫(kù)的一部分。想瀏覽這個(gè)函數(shù)的完整代碼,你可以看“編譯、注冊(cè)和安裝自定義任務(wù)”部分:

    [system.runtime.interopservices.comunregisterfunctionattribute()]

    static void unregisterserver(type t)

    {

    //code to unregister custom task

    }

      免注冊(cè)函數(shù)通過(guò)從注冊(cè)表中刪除下面鍵值從dts任務(wù)緩存中移出任務(wù)

    hkey_current_user/software/microsoft/microsoft sql server/80/dts/enumeration/tasks/a39847f3-5845-4459-a25e-de73a8e3cd48

      最后,自定義的任務(wù)像dual_interface com組件一樣被開(kāi)放。您從所有的類的public,非靜態(tài)的字段,屬性和方法創(chuàng)建一個(gè)默認(rèn)的接口。在下面的一行代碼在自定義任務(wù)源文件中using應(yīng)用之后:

    [assembly:classinterface(classinterfacetype.autodual)]

      這部分的代碼已經(jīng)完全列舉了。

      增加功能性的自定義任務(wù)

      本文“編譯、注冊(cè)和安裝自定義任務(wù)”部分包含一個(gè)簡(jiǎn)單的dts自定義任務(wù)代碼。 任務(wù)有兩個(gè)屬性:name 和description,description屬性的值就會(huì)出現(xiàn)在消息框中。這個(gè)例子的描述了一個(gè)最小化的代碼你可以使用已有的功能性的dts定義任務(wù)。然而,你可以通過(guò)執(zhí)行customtaskui接口創(chuàng)建一個(gè)用戶界面,但是那并不作討論。通過(guò)只執(zhí)行自定義的接口,dts設(shè)計(jì)者為自定義任務(wù)創(chuàng)建一個(gè)默認(rèn)的有戶界面。

      所有的dts自定義任務(wù)執(zhí)行自定義任務(wù)接口。自定義的用戶接口是由兩個(gè)屬性,一個(gè)集合和一個(gè)方法:

      1、 name和description屬性;

      2、 properties集;

      3、 execute方法。

      所有的自定義任務(wù)應(yīng)該執(zhí)行屬性、屬性集和execute方法。

      編譯、注冊(cè)和安裝自定義任務(wù)

    using system;
    using system.runtime.interopservices;
    using microsoft.sqlserver.dtspkg80;
    using microsoft.win32;
    using system.windows.forms;

    [assembly:classinterface(classinterfacetype.autodual)]

    namespace dts
    {
     [guid("38ed4f80-9ef4-4752-8478-65d2db3ba7dd"), comvisible(true)] //guid is created by using guidgen.exe
     [progid("dts.simplecustomtask")]
     public class simplecustomtask : customtask
     {
      private string name;
      private string description;
      public simplecustomtask()
      {
       name = "";
       description = "simplecustomtask description";
      }
      public void execute(object ppackage, object ppackageevents, object ppackagelog, ref microsoft.sqlserver.dtspkg80.dtstaskexecresult ptaskresult)

      {
       //assume failure at the outset
       ptaskresult= dtstaskexecresult.dtstaskexecresult_failure;
       try
       {
       package2 package = (package2) ppackage;
       packageevents packageevents = (packageevents) ppackageevents;
       packagelog packagelog = (packagelog) ppackagelog;
       messagebox.show(description);
       }
       //first catch com exceptions, and then all other exceptions
       catch(system.runtime.interopservices.comexception e)
       {
        console.writeline(e);
       }
       catch(system.exception e)
       {
        console.writeline(e);
       }

        //return success
       ptaskresult = dtstaskexecresult.dtstaskexecresult_success;
      }

      public string description
       {
       get { return this.description; }
       set { this.description = value; }
      }

      public string name
      {
       get { return name; }
       set { this.name = value; }
      }

      public microsoft.sqlserver.dtspkg80.properties properties
      {
       get { return null; }
      }

      [system.runtime.interopservices.comvisible(false)]
      override public string tostring()
      {
       return base.tostring();
      }

      //registration function for custom task.
      [system.runtime.interopservices.comregisterfunctionattribute()]
      static void registerserver(type t)
      {
       try
       {
        const string task_cache = "software//microsoft//microsoft sql server//80//dts//enumeration//tasks";
    const string catid_dtscustomtask = "{10020200-eb1c-11cf-ae6e-00aa004a34d5}";
    string guid = "{" + t.guid.tostring() + "}";
    guid = guid.toupper();
    console.writeline("registerserver {0}", guid);
    registrykey root;
    registrykey rk;
    registrykey nrk;
    // add com category in hkey_classes_root

    root = registry.classesroot;
    rk = root.opensubkey("clsid//" + guid + "//implemented categories", true);
    nrk = rk.createsubkey(catid_dtscustomtask);
    nrk.close();
    rk.close();
    root.close();
    // add to dts cache in hkey_current_user
    root = registry.currentuser;
    rk = root.opensubkey(task_cache, true);
    nrk = rk.createsubkey(guid);
    nrk.setvalue("", t.fullname);
    nrk.close();
    rk.close();
    root.close();
    simplecustomtask ct = new simplecustomtask();
      root = registry.classesroot;
    rk = root.opensubkey("clsid//" + guid, true);
    rk.setvalue("dtstaskdescription", ct.description);
    nrk.close();
      rk.close();
    root.close();
       }
       catch(exception e)
       {
        system.console.writeline(e.tostring());
       }
      }

     //unregistration function for custom task.
     [system.runtime.interopservices.comunregisterfunctionattribute()]
     static void unregisterserver(type t)
     {
      try
      {
    const string task_cache = "software//microsoft//microsoft sql server//80//dts//enumeration//tasks";
    string guid = "{" + t.guid.tostring() + "}";
    guid = guid.toupper();
    console.writeline("unregisterserver {0}", guid);
    registrykey root;
    registrykey rk;
    // delete from dts cache in hkey_current_user
    root = registry.currentuser;
    rk = root.opensubkey(task_cache, true);
    rk.deletesubkey(guid, false);
    rk.close();
    root.close();
      }
      catch(exception e)
      {
    system.console.writeline(e.tostring());
      }
     }
    }

    }


    發(fā)表評(píng)論 共有條評(píng)論
    用戶名: 密碼:
    驗(yàn)證碼: 匿名發(fā)表
    主站蜘蛛池模板: 长顺县| 全椒县| 铜陵市| 清丰县| 高陵县| 桂阳县| 扶沟县| 蒙阴县| 阿勒泰市| 天津市| 囊谦县| 蓝山县| 白朗县| 利川市| 阿克苏市| 襄城县| 太仆寺旗| 含山县| 响水县| 岱山县| 壶关县| 乐昌市| 金寨县| 嘉鱼县| 松原市| 乐东| 西畴县| 永平县| 娱乐| 松江区| 米易县| 延长县| 八宿县| 哈巴河县| 石景山区| 理塘县| 黑龙江省| 西畴县| 康定县| 佛学| 镇坪县|