【发布时间】:2013-01-15 22:01:47
【问题描述】:
我正在使用 powershell 将基于 Visual Studio 2012 构建的 dacpac 部署到 SQL Azure,并遇到了我认为可能与某些版本不兼容有关的问题。当我从 Visual Studio 中发布时,发布工作正常,但在我使用 powershell 时抛出异常。
这是我在 Powershell 中所做的事情
[System.Reflection.Assembly]::Load("Microsoft.SqlServer.Management.Sdk.Sfc, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91") | out-null
[System.Reflection.Assembly]::Load("Microsoft.SqlServer.Smo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91") | out-null
[System.Reflection.Assembly]::Load("Microsoft.SqlServer.ConnectionInfo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91") | out-null
[System.Reflection.Assembly]::Load("Microsoft.SqlServer.Management.Dac, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91") | out-null
Trap
{
PrintException($_.Exception);
$fileStream.Close()
return;
}
$sqlServerFullName = $sqlServerName + ".database.windows.net"
$serverConnection = New-Object Microsoft.SqlServer.Management.Common.ServerConnection($sqlServerFullName, $adminLogin, $admingPwd)
$serverconnection.Connect()
$dacstore = New-Object Microsoft.SqlServer.Management.Dac.DacStore($serverConnection)
$fileStream = [System.IO.File]::Open($dacpacPath,[System.IO.FileMode]::OpenOrCreate)
Write-Host "Reading contents from $dacpacPath..."
$dacType = [Microsoft.SqlServer.Management.Dac.DacType]::Load($fileStream)
上面代码中的最后一行是由于以下错误(内部异常值)而崩溃并且没有进一步处理
The stream cannot be read to construct the DacType.
There is an error in XML document (2, 2).
<DacType xmlns='http://schemas.microsoft.com/sqlserver/dac/Serialization/2012/0
2'> was not expected.
这是我正在使用的 powershell ISE 中的 $PSVersionTable
Name Value
---- -----
PSVersion 2.0
PSCompatibleVersions {1.0, 2.0}
BuildVersion 6.1.7601.17514
CLRVersion 4.0.30319.17929
WSManStackVersion 2.0
PSRemotingProtocolVersion 2.1
SerializationVersion 1.1.0.1
想知道当我使用 Visual Studio 2012 部署时使用 Powershell 进行部署时可能会导致此问题的原因
附: - 使用我在互联网上找到的带有 dacpac 文件的相同脚本,powershell 部署工作正常,该文件显然是针对 SQL 2005 版本的
【问题讨论】:
-
您是否尝试过使用 WindowsAzurePowerShell 命令行开关(可通过 Web 平台安装程序下载,或在 github 上:github.com/windowsazure/azure-sdk-tools
-
SQl 2012 更改了 dacpac API 和文件架构,并且与以前的 SQL 版本完全不兼容,反之亦然。因此,如果您将 SQL 2008 R2 dacpac DLL 与 2012 SQL dacpac 一起使用,它将完全爆炸
-
@Nick - 你有关于不兼容的任何其他信息吗?
-
老实说,时间太长了,我不记得细节了。我确实记得 Visual Studio 中的 SQL Data Tools 版本控制在我发现问题时发挥了作用 - 抱歉。
-
您是否尝试过通过提升的命令(明确以管理员身份)运行 powershell ISE?您使用的该用户可能还需要访问您的 Azure 部署环境。
标签: sql-server powershell azure-sql-database dac azure-powershell