簡體   English   中英

通過 MS Access VBA 創建並動態修改.dtsx 文件

[英]Create and dynamically modify .dtsx file via MS Access VBA

我正在嘗試通過 MS Access VBA 使用具有動態執行文件名的單個 .dtsx 文件。 我正在嘗試將其作為已經在工作中創建的 Access 工具的一部分。 當我

通過將每個文件重命名為單個、唯一的名稱、運行.dtsx,然后將名稱改回來,我已經能夠解決將.dtsx 鏈接到同一文件夾中的多個文件的問題。 但是,不一定保證文件夾目錄,因為許多其他用戶可能會使用該工具。

Imports Microsoft.SqlServer.Dts.Runtime  

Module ApplicationTests  

  Sub Main()  

    ' The variable pkg points to the location of the  
    ' ExecuteProcess package sample that was installed with  
    ' the SSIS samples.  
    Dim pkg As String = _  
      "C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services" & _  
      "\Package Samples\ExecuteProcess Sample\ExecuteProcess\UsingExecuteProcess.dtsx"  

    Dim app As Application = New Application()  
    Dim p As Package = app.LoadPackage(pkg, Nothing)  

    ' Now that the package is loaded, we can query on  
    ' its properties.  
    Dim n As Integer = p.Configurations.Count  
    Dim p2 As DtsProperty = p.Properties("VersionGUID")  
    Dim pl As DTSProtectionLevel = p.ProtectionLevel  

    Console.WriteLine("Number of configurations = " & n.ToString())  
    Console.WriteLine("VersionGUID = " & CType(p2.GetValue(p), String))  
    Console.WriteLine("ProtectionLevel = " & pl.ToString())  
    Console.Read()  

  End Sub  

End Module  

這是我在https://docs.microsoft.com/en-us/sql/integration-services/building-packages-programmatically/creating-a-package-programmatically?view=sql-server-ver15找到的代碼,但是它僅適用於我無法訪問的 VB.Net。 我希望模仿這個想法,但在訪問 VBA - 創建/修改 SSIS package。

所以我的快速搜索證實了我認為是真的 - VBA/VBScript 不能與 object model 一起使用,您正嘗試使用Imports Microsoft.SqlServer.Dts.Runtime

您可以在 DTS 程序集之間編寫一個橋梁,以便您可以在 VBA 中使用它,但考慮到您正在嘗試使用 Access 的 VBA,因為您無法使用適當的工具,好吧,有一個循環引用。

備擇方案。

SQL 服務器數據工具 SSDT 是免費的。 它是用於創作 SSIS 包的工具。 It has a Script Task that uses .NET and has the references to the managed object model already set so write a package that modifies another package.

表達式 - SSIS package 中的大多數 object 都支持表達式,因此只要有足夠的肘部潤滑脂,您就可以啟動並運行一些非常動態的包。

Biml - 商業智能標記語言是 Visual Studio 的免費插件,它采用不同的方法來制作包。

一種常見的數據處理模式是數據的截斷和重新加載。 SSIS 的許多新手想要一個單一的 package,它可以接受任何來源並將其與目的地相匹配,他們希望它是動態的 - 指定一個新的來源/目的地和奇跡發生。 引擎不支持。 Biml 讓您做的是定義模式 - 截斷表 -> 帶有平面文件源的數據流到 OLE DB 目標。 現在您已經有了自己的模式,然后您可以使用元數據(這些文件 go 到這些目標表)並構建 N 個包。 你會得到大量的包,但你並不關心,因為困難的部分是定義模式和收集元數據。 這些包幾乎是一次性工件,因為它們將成為您開發的整個生態系統的標准。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM