11

私は、Visual Studio 2012 で構築された dacpac を、powershell を使用して SQL Azure にデプロイしていて、バージョンの非互換性に関連していると思われる問題に遭遇しています。パブリッシュはビジュアル スタジオから実行すると正常に動作しますが、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 を使用してデプロイすると、この問題の原因は何なのか疑問に思っています。

PS - powershell デプロイは、インターネットで見つけた dacpac ファイルと同じスクリプトを使用して正常に動作しますが、これは明らかに SQL 2005 バージョンをターゲットにしていました

4

2 に答える 2

4

最新の SSDT 2015 ( https://msdn.microsoft.com/en-us/mt186501 )をインストールした場合。Visual Studio を使用して生成できる発行プロファイル用の便利なオプションが多数あるため、強くお勧めします。

以下を使用して、Powershell を使用してファイルを Azure に発行できます。

$sqlpackage = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\120\sqlpackage.exe"

$dbserver = "<Azure DB Location>"  
$database = "<name of DB on Server>"

# UNC Paths

$dbProfile = "<Path to your Publish Profile>"
$mydacpac = "<location of the dacpac>" 

# Publish Command

& $sqlpackage /Action:Publish /tsn:$dbServer /tdn:$database /sf:$mydacpac/pr:$dbProfile /variables:myVariable=1

PS:& Pradebbanが言及したInvoke-Expressionのように機能します

于 2015-07-24T17:56:30.150 に答える