Powershell Octopus Deploy.ps1 DACPAC部署失败

Powershell Octopus Deploy.ps1 DACPAC部署失败,powershell,deployment,octopus-deploy,dacpac,Powershell,Deployment,Octopus Deploy,Dacpac,我在TeamCity上使用Octopus将数据库部署到我们的生产环境中,但它总是给出一个错误 以下是Deploy.ps1代码: $dbName = $OctopusParameters['DBName'] $dbUser = $OctopusParameters['AdminDBUsername'] $dbPassword = $OctopusParameters['AdminDBPassword'] $dbSource = $OctopusParameters['DBDataSource']

我在TeamCity上使用Octopus将数据库部署到我们的生产环境中,但它总是给出一个错误

以下是Deploy.ps1代码:

$dbName = $OctopusParameters['DBName']
$dbUser = $OctopusParameters['AdminDBUsername']
$dbPassword = $OctopusParameters['AdminDBPassword']
$dbSource = $OctopusParameters['DBDataSource']

# Set params
if (! $dbName)
{
    Write-Host "Missing required variable dbName" -ForegroundColor Yellow
    exit 1
}
if (! $dbUser)
{
    Write-Host "Missing required variable dbUser" -ForegroundColor Yellow
    exit 1
}
if (! $dbPassword)
{
    Write-Host "Missing required variable dbPassword" -ForegroundColor Yellow
    exit 1
}
if (! $dbSource)
{
    Write-Host "Missing required variable dbSource" -ForegroundColor Yellow
    exit 1
}

# Add the DLL
# For 64-bit machines
Add-Type -path ((Get-Item -Path ".\" -Verbose).FullName + "\bin\Microsoft.SqlServer.TransactSql.ScriptDom.dll")
Add-Type -path ((Get-Item -Path ".\" -Verbose).FullName + "\bin\Microsoft.SqlServer.Dac.dll")

# Create the connection string
$d = New-Object Microsoft.SqlServer.Dac.DacServices ("data source=" + $dbSource + ";User Id = " + $dbUser + ";pwd=" + $dbPassword)

#Load the dacpac
$dacpac = ((Get-Item -Path ".\" -Verbose).FullName + "\DeployScripts\Database.dacpac")
$dacpacoptions = ((Get-Item -Path ".\" -Verbose).FullName + "\DeployScripts\publish.xml")

#Load dacpac from file & deploy to database
$dp = [Microsoft.SqlServer.Dac.DacPackage]::Load($dacpac)

#Read a publish profile XML to get the deployment options
$dacProfile = [Microsoft.SqlServer.Dac.DacProfile]::Load($dacpacoptions)

# Deploy the dacpac
$d.Deploy($dp, $dbName, $TRUE, $dacProfile.DeployOptions)
以下是发布配置文件,以备不时之需:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <IncludeCompositeObjects>True</IncludeCompositeObjects>
    <TargetDatabaseName>MyDatabase</TargetDatabaseName>
    <DeployScriptFileName>MyDatabase.sql</DeployScriptFileName>
    <ProfileVersionNumber>1</ProfileVersionNumber>
    <BlockWhenDriftDetected>True</BlockWhenDriftDetected>
    <RegisterDataTierApplication>True</RegisterDataTierApplication>
  </PropertyGroup>
</Project>

真的
我的数据库
MyDatabase.sql
1.
真的
真的
下面是我得到的错误:

使用“4”参数调用“Deploy”时出现异常:

“生成部署计划时出错。部署无法继续。”

在Deploy.ps1:60字符:2

$d.Deploy($dp、$dbName、$TRUE、$dacProfile.DeployOptions)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CategoryInfo:NotSpecified:(:)[],ParentContainerRorRecordException

FullyQualifiedErrorId:DacServicesException


有人知道这是什么原因吗?如何修复它?提前谢谢

好了,伙计们,我知道了。以下是我所做的:

在ps1文件中,添加一个try-catch块,其中$d.Deploy的调用方式如下:

 try
 {
     # Deploy the dacpac
     $d.Deploy($dp, $dbName, $TRUE, $dacProfile.DeployOptions)
 }
 catch
 {
     Write-Host "LoadException";
     $Error | format-list -force
     Write-Host $Error[0].Exception.ParentContainsErrorRecordException;
 }
这样做告诉我sqlproj文件的目标是Sql Server 2014,但部署到的数据库是Sql Server 2012。只需进入sql项目文件的属性并对其进行更改,使其针对sql Server 2012,现在就可以工作了!胡萨