是否可以使用Microsoft.Sqlserver.Management.Smo发布dacpac文件?

时间:2016-06-08 20:21:00

标签: .net sql-server smo dacpac

我环顾四周但却找不到任何东西。我无权访问

Microsoft.SqlServer.Dac

,遗憾的是,由于权限问题,我无法将其下载到我正在处理的计算机上。

编辑还应该提到我正在使用SP4和SQL Server 2008运行VS 2012.我安装的VS安装了SSDT,但由于某种原因,Microsoft.SqlServer.Dac DLL不是安装。

2 个答案:

答案 0 :(得分:1)

您可以使用带有Powershell的SMO发布DacPac,以下是documentation中示例的副本。

## Set a SMO Server object to the default instance on the local computer.  
CD SQLSERVER:\SQL\localhost\DEFAULT  
$srv = get-item .  

## 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)  

## Load the DAC package file.  
$dacpacPath = "C:\MyDACs\MyApplication.dacpac"  
$fileStream = [System.IO.File]::Open($dacpacPath,[System.IO.FileMode]::OpenOrCreate)  
$dacType = [Microsoft.SqlServer.Management.Dac.DacType]::Load($fileStream)  

## Subscribe to the DAC deployment events.  
$dacstore.add_DacActionStarted({Write-Host `n`nStarting at $(get-date) :: $_.Description})  
$dacstore.add_DacActionFinished({Write-Host Completed at $(get-date) :: $_.Description})  

## Deploy the DAC and create the database.  
$dacName  = "MyApplication"  
$evaluateTSPolicy = $true  
$deployProperties = New-Object Microsoft.SqlServer.Management.Dac.DatabaseDeploymentProperties($serverconnection,$dacName)  
$dacstore.Install($dacType, $deployProperties, $evaluateTSPolicy)  
$fileStream.Close()  

答案 1 :(得分:0)

如果你不能运行安装程序,你可以复制dll,或者你甚至不能这样做吗?

您还可以通过针对数据库生成部署脚本或对其进行脱机备份,从另一台计算机运行部署。