我正在尝试制作使用SqlPackage
通过TFS Deployer服务部署数据库的PowerShell脚本。如果直接从命令行执行脚本,但是当TFS Deployer尝试执行脚本时脚本失败,则两个案例都使用相同的用户帐户。
该服务作为控制台应用程序以测试模式(TfsDeployer -d
)运行,但在作为Windows服务运行时也会失败。
这是日志文件(捕获的SqlPackage
输出和PowerShell脚本中捕获的异常):
11/18/2012 17:51:49 | Publishing to database 'databaseName' on server 'machineName'.
11/18/2012 17:51:56 | An error occurred while the batch was being executed.
11/18/2012 17:51:56 | System.Management.Automation.RemoteException: *** Could not deploy package.
这是我能够收集的唯一信息。错误代码(HRESULT)在捕获的异常中不存在。
PowerShell脚本是这样的:
try{
$cmd = Join-Path (Get-Item "Env:ProgramFiles(x86)").Value "Microsoft SQL Server\110\DAC\bin\SqlPackage.exe"
$src = Join-Path $source "db.dacpac"
$cfg = Join-Path $source "db.publish.xml"
&$cmd /Action:Publish /SourceFile:$src /Profile:$cfg 2>&1 | ForEach-Object -Process {
Write-Log $_
}
}
catch [Exception] {
Write-Log $_.Exception.ToString()
if($_.Exception.HResult) {
Write-Log "Code: $($_.Exception.HResult.ToString('X'))"
}
}