下午好,
我创建了一个包含单个包的SSIS项目。当我从服务器手动执行时,SSIS项目和包正如我所期望的那样工作。我想如果我在服务器上设置环境变量并将其映射到项目。除非另有说明,否则每次执行包时项目都会使用这些变量。以下代码是我的VB代码
'VB.Net code
Imports System.Data.SqlClient
Imports Microsoft.SqlServer.Management.IntegrationServices
Imports System.Collections.ObjectModel
Public Class Form1
Private Sub StartPackageButton_Click(sender As System.Object, e As System.EventArgs) Handles StartPackageButton.Click
Try
' Connection to the database server where the packages are located
Dim ssisConnection As New SqlConnection("Data Source=" + txtServerName.Text + ";Integrated Security=SSPI;")
' SSIS server object with connection
Dim ssisServer As New IntegrationServices(ssisConnection)
' The reference to the package which you want to execute
Dim ssisPackage As PackageInfo = ssisServer.Catalogs("SSISDB").Folders("SSIS_PROJECTS").Projects("AgressoExport").Packages("File56Export.dtsx")
' Add a parameter collection for 'system' parameters (ObjectType = 50), package parameters (ObjectType = 30) and project parameters (ObjectType = 20)
Dim executionParameters As New Collection(Of PackageInfo.ExecutionValueParameterSet)
' Add execution parameter to override the default asynchronized execution. If you leave this out the package is executed asynchronized
Dim executionParameter1 As New PackageInfo.ExecutionValueParameterSet
executionParameter1.ObjectType = 50
executionParameter1.ParameterName = "SYNCHRONIZED"
executionParameter1.ParameterValue = 1
executionParameters.Add(executionParameter1)
' Add execution parameter (value) to override the default logging level (0=None, 1=Basic, 2=Performance, 3=Verbose)
Dim executionParameter2 As New PackageInfo.ExecutionValueParameterSet
executionParameter2.ObjectType = 50
executionParameter2.ParameterName = "LOGGING_LEVEL"
executionParameter2.ParameterValue = 3
executionParameters.Add(executionParameter2)
' Add execution parameter (value) to override the default logging level (0=None, 1=Basic, 2=Performance, 3=Verbose)
Dim executionParameter3 As New PackageInfo.ExecutionValueParameterSet
If (Trim(txtPreviousID.Text) <> "") Then
executionParameter3.ObjectType = 20
executionParameter3.ParameterName = "PreviousBatchID"
executionParameter3.ParameterValue = txtPreviousID.Text
executionParameters.Add(executionParameter3)
End If
' Get the identifier of the execution to get the log
Dim executionIdentifier As Long = ssisPackage.Execute(False, Nothing, executionParameters)
' Loop through the log and add the messages to the listbox
For Each message As OperationMessage In ssisServer.Catalogs("SSISDB").Executions(executionIdentifier).Messages
SSISMessagesListBox.Items.Add(message.MessageType.ToString() + ": " + message.Message)
Next
Catch ex As Exception
If ex.InnerException IsNot Nothing Then
SSISMessagesListBox.Items.Add(ex.Message.ToString() + " : " + ex.InnerException.Message.ToString())
Else
SSISMessagesListBox.Items.Add(ex.Message.ToString())
End If
End Try
End Sub
End Class
我开始认为在SSIS方面我没有正确理解环境。我的环境在各自的服务器上设置为TEST和PROD,相同的变量名称映射到相同的参数但具有不同的值。我开始相信我应该在TEST和PROD服务器上都有相同的环境名称,我也会使用我的VB代码来引用它。尽管如此,我还是无法找到如何使用VB引用环境。
我很感激有关此事的任何帮助。
干杯, 乔纳森
答案 0 :(得分:0)
出于此目的,ssis已经提供了配置功能,您只需为不同的环境创建单独的cofig文件或数据库条目。
答案 1 :(得分:0)
您需要将程序包的1. net-ssh-4.0.0.alpha4
属性设置为环境的ID。
要获取环境ID,请尝试:
reference
答案 2 :(得分:0)
能够在Visual Basic .NET程序中使用环境。您需要声明Environment Reference并将引用传递给SSIS包的Execute方法。
以下代码块是如何完成的:
Dim re As EnvironmentReference
re = ssisServer.Catalogs("SSISDB").Folders("SSIS_PROJECTS").Projects("AgressoExport").References("AgressoExport", ".")
Dim executionIdentifier As Long = ssisPackage.Execute(False, re, executionParameters)
SSISDB是目录名称,SSIS_PROJECTS是我正在使用的目录下的文件夹名称。 AgressoExport是我的项目名称。 (“AgressoExport”,“。”)是指环境文件夹根目录下我的项目名为AgressoExport的环境。
干杯