我正在尝试以编程方式执行位于数据库中的SSIS包。
我正在使用此API:
Imports Microsoft.SqlServer.Dts.Runtime
我有一个描述要打包的路径(在数据库中)的图像,但我无法弄清楚如何在 LoadFromSqlServer 方法中正确设置 packagePath 属性。
以下是描述数据库中包路径的图像:
答案 0 :(得分:6)
您需要添加对Microsoft.SqlServer.Management.IntegrationServices的引用。对我来说,它不会出现在SQL Server文件夹中,我只能在GAC中找到它。
C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Management.IntegrationServices\11.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Management.IntegrationServices.dll
还有从该程序集到
的依赖关系 C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Management.Sdk.Sfc\11.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Management.Sdk.Sfc.dll
Sub Main()
'
' Do not fault me for my poor VB skills nor my lack of error handling
' This is bare bones code adapted from
' http://blogs.msdn.com/b/mattm/archive/2011/11/17/ssis-and-powershell-in-sql-server-2012.aspx
Dim folderName As String
Dim projectName As String
Dim serverName As String
Dim packageName As String
Dim connectionString As String
Dim use32BitRuntime As Boolean
Dim executionId As Integer
Dim integrationServices As Microsoft.SqlServer.Management.IntegrationServices.IntegrationServices
Dim catalog As Microsoft.SqlServer.Management.IntegrationServices.Catalog
Dim catalogFolder As Microsoft.SqlServer.Management.IntegrationServices.CatalogFolder
Dim package As Microsoft.SqlServer.Management.IntegrationServices.PackageInfo
' Dimensions in your example
folderName = "SSISHackAndSlash"
' dimCalendar in your example
projectName = "SSISHackAndSlash2012"
serverName = "localhost\dev2012"
' dimCalendar in your example (no file extension)
packageName = "TokenTest.dtsx"
connectionString = String.Format("Data Source={0};Initial Catalog=msdb;Integrated Security=SSPI;", serverName)
integrationServices = New Microsoft.SqlServer.Management.IntegrationServices.IntegrationServices(New System.Data.SqlClient.SqlConnection(connectionString))
' There is only one option for an SSIS catalog name as of this posting
catalog = integrationServices.Catalogs("SSISDB")
' Find the catalog folder. Dimensions in your example
catalogFolder = catalog.Folders(folderName)
' Find the package in the project folder
package = catalogFolder.Projects(projectName).Packages(packageName)
' Run the package. The second parameter is for environment variables
executionId = package.Execute(use32BitRuntime, Nothing)
End Sub
答案 1 :(得分:1)
如果要查找在SQL Server中部署的程序包位置。
忽略服务器名称,因为它将是LoadFromSqlServer
方法的参数。
所以包路径应该是:\ Stored Package \ MSDB \ Data Collector \ PerfCountersUpload。
希望这有帮助。
答案 2 :(得分:1)
除了billinkc answer。
以下是代码的C#版本:
string folderName = "name";
string projectName = "name";
string serverName = "localhost";
string packageName = "name";
string connectionString = string.Format("Data Source={0};Initial Catalog=msdb;Integrated Security=SSPI;", serverName);
var integrationServices = new IntegrationServices(newSystem.Data.SqlClient.SqlConnection(connectionString));
var catalog = integrationServices.Catalogs["SSISDB"];
var catalogFolder = catalog.Folders[folderName];
var package = catalogFolder.Projects[projectName].Packages[packageName];
long execId = package.Execute(false, null);
在我的情况下,我不得不添加4个dll:
Microsoft.SqlServer.ConnectionInfo.dll
Microsoft.SqlServer.Management.IntegrationServices.dll
Microsoft.SqlServer.Management.Sdk.Sfc.dll
Microsoft.SqlServer.Smo.dll
可以找到所有依赖项C:\Windows\assembly\GAC_MSIL\