Hi,
I'm trying to follow the msdn documentation to deploy a dacpac on SQL Server 2012 which is installed on my local machine. Here's the link to the documentation: http://technet.microsoft.com/en-us/library/ee210569(v=sql.110).aspx
The script I try to execute is:
param (
[string]$dacpacPath = $(throw "-dacpacPath is required."),
[string]$dacName = $(throw "-dacName is required."),
[string]$serverName = $(throw "-servereName is required.")
)
$ErrorActionPreference = "Stop"
Push-Location
Import-Module sqlps -DisableNameChecking
Pop-Location
$srv = Get-Item "SQLSERVER:\SQL\$serverName"
## Open a Common.ServerConnection to the same instance.
$serverconnection = New-Object Microsoft.SqlServer.Management.Common.ServerConnection($srv.ConnectionContext.SqlConnectionObject)
$serverconnection.Connect()
$dacstore = New-Object Microsoft.SqlServer.Management.Dac.DacStore($serverconnection)
## Subscribe to the DAC events.
$dacstore.add_DacActionStarted({Write-Host `n`nStarting at $(get-date) :: $_.Description})
$dacstore.add_DacActionFinished({Write-Host Completed at $(get-date) :: $_.Description})
## Delete previous DAC if exists and drop the database
$dacstore.Uninstall($dacName, [Microsoft.SqlServer.Management.Dac.DacUninstallMode]::DropDatabase)
## Load the DAC package file.
$fileStream = [System.IO.File]::Open($dacpacPath,[System.IO.FileMode]::OpenOrCreate)
$dacType = [Microsoft.SqlServer.Management.Dac.DacType]::Load($fileStream)
## Deploy the DAC and create the database.
$evaluateTSPolicy = $true
$deployProperties = New-Object Microsoft.SqlServer.Management.Dac.DatabaseDeploymentProperties($serverconnection, $dacName)
$dacstore.Install($dacType, $deployProperties, $evaluateTSPolicy)
$fileStream.Close()
## END SCRIPT
When I try to run the script from powershell console I get the following exception:
New-Object : Cannot find type [Microsoft.SqlServer.Management.Dac.DacStore]: verify that the assembly containing this type is loaded.
At C:\src\commerce\private\CommerceSearch\relevance\MTurkJudgmentSystem\Publish\deploy-db.ps1:19 char:13
+ $dacstore = New-Object Microsoft.SqlServer.Management.Dac.DacStore($serverconnec ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
As the documentation states, calling Import-Module sqlps -DisableNameChecking should load all the assemblies automatically, but for some reason this doesn't happen.
I've tried installing packages from here http://www.microsoft.com/en-us/download/details.aspx?id=39976 but it didn't help.
What am I missing from reading the docs?
Thanks.