2017-11-02 21 views
0

My PowershellスクリプトはSSISパッケージを実行しますが、まず環境変数をオーバーライドします。 "EnvironmentInfo [@ Name = 'MyVariable'] 'オブジェクトのOperation' Alter 'が実行中に失敗しました"という一般的なエラーメッセージで、EnvironmentInfoオブジェクトのAlterメソッドが失敗します。Powershellエラー設定SSISパッケージ実行の環境変数

また、環境変数を削除してProjectパラメータを変更しようとしましたが、ProjectオブジェクトのAlterメソッドで同じエラーが発生しました。

これは、1)SQL Server 2012の32ビット版の使用の欠点、または2)アクセス許可の問題のいずれかと思われます。

私は確信して作ったWindowsのアカウントなどSSISDBデータベースとSSISカタログプロジェクト、および子フォルダ、環境、上の完全な権限を持つ実行

エラー上の任意のアイデアや私が多くを得ることができる方法詳細は? Windowsイベントログには何も表示されません。

# Variables 
$ServerInstance = "MyServer" 
$32bitSQLServer = "false" #use #null for 32-bit 
$SSISNamespace = "Microsoft.SqlServer.Management.IntegrationServices" 
$FolderName = "MyFolder" 
$ProjectName = "MyProject" 
$PackageName = "MyPackage.dtsx" 
$EnvironmentName = "MyEnvironment" 
$VariableName = "MyVariable" 
$VariableValue = Read-Host "What is the new environment variable value? " 

# Create a connection to the server - Have to use Windows Authentication in order to Execute the Package 
$sqlConnectionString = ` 
    "Data Source=" + $ServerInstance + ";Initial Catalog=master;Integrated Security=SSPI;" 
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString 

# Create the Integration Services object 
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.IntegrationServices") 
$integrationServices = New-Object $SSISNamespace".IntegrationServices" $sqlConnection 

# Get the Integration Services catalog 
$catalog = $integrationServices.Catalogs["SSISDB"] 

# Get the folder 
$folder = $catalog.Folders[$FolderName] 

# Get the project 
$project = $folder.Projects[$ProjectName] 

# Get the environment 
$environment = $folder.Environments[$EnvironmentName] 

# Get the environment reference 
$environmentReference = $project.References.Item($EnvironmentName, $FolderName)    
$environmentReference.Refresh() 

# Get the package 
$package = $project.Packages[$PackageName] 

# Set the Environment Variable 
$environment.Variables[$VariableName].Value = $VariableValue 
$environment.Alter() 

# Execute the package 
Write-Host "Running Package " $PackageName "..." 
$result = $package.Execute($32bitSQLServer, $environmentReference) 

# Alternate approach, also not working 
# $project.Parameters[$VariableName].Set([Microsoft.SqlServer.Management.IntegrationServices.ParameterInfo+ParameterValueType]::Literal,$VariableValue) 
# $project.Alter() 
# $result = $package.Execute($32bitSQLServer, $environmentReference) 

Write-Host "Done." 

答えて

0

私は自分のエラーの答えを見つけました。私のGAC(Windows \ assembly)にアセンブリMicrosoft.SqlServer.Management.IntegrationServicesの複数のバージョン(11.0.0.0,12.0.0.0,13.0.0.0)がありました。 SSISDBカタログのスキーマを調べると、バージョン12.0.5000.0となり、アセンブリの12.0.0.0バージョンが必要でした。私が使っていたコード:

[Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.IntegrationServices") 

は、間違ったバージョン(おそらく13.0.0.0)をロードしたので、私は明示的に12.0.0.0たSSISのこのインストールに一致するアセンブリのバージョン、ロードするために必要な:

[System.Reflection.Assembly]::Load("Microsoft.SqlServer.Management.IntegrationServices, Version=12.0.0.0, Culture=neutral, processorArchitecture=MSIL, PublicKeyToken=89845dcd8080cc91") 
0

ちょうどパッケージのパラメータを変更し、環境変数を心配しないでください:

は、ここに私のコードです。私はそれがサーバー上のパッケージに格納されている値を変更しないと確信しています。オブジェクトは$package変数に保持されています。このようなもの:

$package.Parameters[$VariableName].Set([Microsoft.SqlServer.Management.IntegrationServices.ParameterInfo+ParameterValueType]::Literal, $VariableValue) 
$package.Alter() 

$execution = $integrationServices.Catalogs['SSISDB'].Executions[$package.Execute($false, ($package.Parent.References[$package_name, $folder_Name]))] 

do { 
    $execution.Refresh() 
} until ($execution.Completed) 
+0

ありがとう、Daveが、私はすでにそれを試しました(post&code参照)。パラメータはProject not Packageにありますので、Projectで値を設定してAlter()を呼び出しましたが、EnvironmentでAlter()を呼び出すのと同じエラーが発生しました。これは、アクセス権や32ビットSQL Serverを使用していることなど、環境に関するものと思われます。 –