Freigeben über


SYSK 398: How to deploy .dacpac to SQL Azure from Azure block blob

Here is a quick-and-dirty (i.e. clean-up and optimize to your liking) way of doing it:

 

Import-Module "sqlps" -DisableNameChecking

$srv = new-object Microsoft.SqlServer.Management.Smo.Server("YOURSERVER.database.windows.net")
$conContext = $srv.ConnectionContext
$conContext.LoginSecure = $FALSE
$conContext.Login = "YOUR_USER"
$conContext.Password = "YOUR_PASSWORD"

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Dac.dll")
$serverconnection = New-Object Microsoft.SqlServer.Management.Common.ServerConnection($srv.ConnectionContext.SqlConnectionObject)
$serverconnection.Connect()

$dacpacPath = "https://YOURNAME.blob.core.windows.net/YOURCONTAINER/YOURFILE.dacpac"
$object = New-Object Net.WebClient
$dpfile = $object.DownloadData($dacpacPath)
$ms = New-Object IO.MemoryStream
$ms.Write($dpfile, 0, $dpfile.Length)

$d = new-object Microsoft.SqlServer.Dac.DacServices($serverconnection)
$dp = [Microsoft.SqlServer.Dac.DacPackage]::Load($ms, 1)
$d.deploy($dp, "test", $TRUE)