2016-05-19 13 views
1

いいえ午後、VBプログラムでSSIS環境変数を使用する

私は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を使って環境を参照する方法を見つけられませんでした。

私は問題について助けていただければ幸いです。目的のSSISのために

乾杯、 ジョナサン

+0

、私は私がEnvironmentReference' ように、この使用 '薄暗い再を行った環境参照のハンドルを取得するために必要なことを発見した' = ssisServer.Catalogs再( "AgressoExport")参照( "AgressoExport"、 "MASTER") 次にExecuteコマンドを次のように変更しました 'Dim executionIdentifier As Long = ssisPackage.Execute(False、re、executionParamters)) ' 残念ながら私はまだ同じエラーが発生していますすべてのパラメータを定義する必要があると述べています。 –

+0

2番目のアップデートで問題が判明しました。私は 'References(" AgressoExport "、"。 ")'を使って、ルートフォルダにAgressoExport環境を必要としていたはずです。 –

答えて

0

あなたは環境のIDであることをパッケージのreferenceプロパティを設定する必要があります。

環境IDトライ取得するには:

DECLARE @environment_id AS BIGINT 
SELECT @environment_id = reference_id FROM SSISDB.internal.environment_references where environment_name = 'your environment name' 
0

Visual Basic .NETのプログラム内の環境を使用できるようにします。環境参照を宣言し、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という環境を指します。

乾杯

は私が解決に少し近い得ていると信じて
関連する問題