找不到Microsoft.SqlServer.Dac.dll

z_lim 2015-08-06 10:01:54
我们现在有个要求是用dacpac 文件来维护数据库(sql server project)
现在我要用powershell 来deploy 这个文件 databasename.dacpac

但是要执行这个需要用到Microsoft.SqlServer.Management.Dac.dll
照道理应该在C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies 下面,可是我机器上没有。。。
谁能知道怎么搞嘛,或者能告诉我怎么用powershell deploy文件 databasename.dacpac的方法

当前系统是sql server 2008 R2
PS: 在sql server 2012 已经实现

微软官方代码2008 R2
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.

## 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()
...全文
83 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
z_lim 2015-08-07
已经解决了,因为机器上装了08和12,所以LOAD DLL的时候要加版本好 [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 非常感谢Tiger_Zhao
回复
z_lim 2015-08-06
当然我也找了可以排除第一句的代码,但是还是会在后面那句出错,代码如下: $logFile = "C:\Temp\DBDeploymentLog.txt" $serverName = "." $userName = "sa" $password = "Pass12345" $dacpacPath = "C:\Users\mzhang149\Documents\SQL Server Management Studio\DAC Packages\SSDWTemp.dacpac" $dacName = "SPStore" # $break = "`n----------------Starting Database Deployment---------------------------------" #Add-Content $logFile $break #$msg = "`nStarting DB creation: " + (date -format "yyyy-MM-dd:HH-mm-ss") # Add-Content $logFile $msg [Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") [Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.Sdk.Sfc") [Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.Dac") [Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") $serverConnection = New-Object Microsoft.SqlServer.Management.Common.ServerConnection($serverName, $userName, $password) $sqlStoreConnection = New-Object Microsoft.SqlServer.Management.Sdk.Sfc.SqlStoreConnection($serverConnection.SqlConnectionObject) $sqlStoreConnection.Connect() Echo ------------Connected----------------- $newDacStore = New-Object Microsoft.SqlServer.Management.Dac.DacStore($sqlStoreConnection) $fileStream = [System.IO.File]::Open($dacpacPath, [System.IO.FileMode]::OpenOrCreate) ECHO -------------Loading FIlestream------------------- $dacType = [Microsoft.SqlServer.Management.Dac.DacType]::Load($fileStream) ECHO -------------Loaded FIlestream------------------- $newDacStore.add_DacActionStarted({Write-Host `n`nStarting at $(get-date) :: $_.Description}) $newDacStore.add_DacActionFinished({Write-Host Completed at $(get-date) :: $_.Description}) $evaluateTSPolicy = $true $deployProperties = New-Object Microsoft.SqlServer.Management.Dac.DatabaseDeploymentProperties($serverconnection,$dacName) $msg = "`nDeploying new instance of database" Add-Content $logFile $msg ECHO -------------DEPLOYING------------------- $newDacStore.Install($dacType, $deployProperties, $evaluateTSPolicy) ECHO -------------DEPLOYING------------------- $fileStream.Close() ##################################################################### # Finished powershell script code ####################################################################
回复
z_lim 2015-08-06
引用 3 楼 Tiger_Zhao 的回复:
你没安装啊:Cannot find DAC assembly Microsoft.SqlServer.Dac.dll
然后你跑官方代码,发现第一句不能跑,跳过第一句,跑到 $dacstore = New-Object Microsoft.SqlServer.Management.Dac.DacStore($serverconnection) 这句,会出错 New-Object : Cannot find an overload for "DacStore" and the argument count: "1". At line:1 char:13 + $dacstore = New-Object Microsoft.SqlServer.Management.Dac.DacStore($serverconnec ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [New-Object], MethodException + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand 能帮我搞搞看吗 官方代码 CD SQLSERVER:\SQL\localhost\DEFAULT $srv = get-item . ## Open a Common.ServerConnection to the same instance. $serverconnection = New-Object Microsoft.SqlServer.Management.Common.ServerConnection($server.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()
回复
Tiger_Zhao 2015-08-06
z_lim 2015-08-06
两边都找过都没有 只找到Microsoft.SqlServer.Management.Dac.DacWizard.dll,Microsoft.SqlServer.Management.Dac.ExtractWizard.dll 直接在C盘下搜索的,所以就是没有
回复
Tiger_Zhao 2015-08-06
32位系统的目录应该是 C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies
回复
相关推荐
发帖
疑难问题
创建于2007-09-28

2.1w+

社区成员

MS-SQL Server 疑难问题
申请成为版主
帖子事件
创建了帖子
2015-08-06 10:01
社区公告
暂无公告