【发布时间】:2018-04-15 13:34:04
【问题描述】:
我的 Powershell 脚本执行 SSIS 包,但首先覆盖环境变量。 EnvironmentInfo 对象上的 Alter 方法失败并显示一般错误消息:“对象 [EnvironmentInfo[@Name='MyVariable']' 上的操作 'Alter' 在执行期间失败。”
我也尝试删除环境变量并更改 Project 参数,但在 Project 对象的 Alter 方法上收到相同的错误。
我怀疑这要么是 1) 使用 32 位版本的 SQL Server 2012 的缺点,要么是 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."
【问题讨论】:
标签: sql-server powershell ssis sql-server-2012