有没有其他人遇到类似的问题,如下所述?
我在使用Powershell部署SQL Server 2012 dacpac数据库升级时遇到问题.详情如下所示:
它是为sql server 2012构建的dacpac文件,当我以管理员身份登录时,我试图通过Powershell从命令行运行它来应用于sql server 2012数据库.
使用"4"参数调用"Deploy"的异常:"无法确定域的身份." 在... so.ps1:17 char:8 + $ d.Deploy($ dp,$ TargetDatabase,$ true,$ DeployOptions)
编辑过的脚本(日志记录和文字更改)如下:
[System.Reflection.Assembly]::LoadFrom("C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\Microsoft.SqlServer.Dac.dll") | Out-Null $d = new-object Microsoft.SqlServer.Dac.DacServices ("... Connection string ...") $TargetDatabase = "databasename" $fullDacPacPath = "c:\temp\...\databasename.dacpac" # Load dacpac from file & deploy to database named pubsnew $dp = [Microsoft.SqlServer.Dac.DacPackage]::Load($fullDacPacPath) $DeployOptions = new-object Microsoft.SqlServer.Dac.DacDeployOptions $DeployOptions.IncludeCompositeObjects = $true $DeployOptions.IgnoreFileSize = $false $DeployOptions.IgnoreFilegroupPlacement = $false $DeployOptions.IgnoreFileAndLogFilePath = $false $DeployOptions.AllowIncompatiblePlatform = $true $d.Deploy($dp, $TargetDatabase,$true,$DeployOptions)
以下是一些支持信息:
Dac框架版本是11.1
在命令行上运行时,脚本会抛出错误:
即.Powershell -File databaseupgrade.ps1
但不在Powershell集成脚本环境中运行时
类似的脚本可以在命令行中为其他dacpac工作.
对网络的研究可能表明它可能与达卡饼的大小有关.工作的那些都小于没有的那个,这个链接提到了一个1.3mb的数字,失败的dacpac的文件大小刚刚超过.如果有人可以确认这是问题,你还可以建议一个解决方案吗?
更新 以下脚本表现出相同的行为即.适用于PS Ide而不是命令行.
[Reflection.Assembly]::LoadWithPartialName("System.IO.IsolatedStorage") $f = [System.IO.IsolatedStorage.IsolatedStorageFile]::GetMachineStoreForDomain(); Write-Host($f.AvailableFreeSpace);
小智.. 6
我相信这个问题(至少在我们的例子中)实际上是当dacpac使用一个利用多个文件组的数据库时.在进行部署比较时,我的假设是它使用IsolatedStorage来处理不同的文件.
上面的链接很有帮助,但这并不是蒂姆·刘易斯在博客上的最后评论那么多.我修改了他的代码以在原生PowerShell中工作.将此置于SMO程序集加载之上应解决此问题:
$replacementEvidence = New-Object System.Security.Policy.Evidence
$replacementEvidence.AddHost((New-Object System.Security.Policy.Zone ([Security.SecurityZone]::MyComputer)))
$currentAppDomain = [System.Threading.Thread]::GetDomain()
$securityIdentityField = $currentAppDomain.GetType().GetField("_SecurityIdentity", ([System.Reflection.BindingFlags]::Instance -bOr [System.Reflection.BindingFlags]::NonPublic))
$securityIdentityField.SetValue($currentAppDomain,$replacementEvidence)
我相信这个问题(至少在我们的例子中)实际上是当dacpac使用一个利用多个文件组的数据库时.在进行部署比较时,我的假设是它使用IsolatedStorage来处理不同的文件.
上面的链接很有帮助,但这并不是蒂姆·刘易斯在博客上的最后评论那么多.我修改了他的代码以在原生PowerShell中工作.将此置于SMO程序集加载之上应解决此问题:
$replacementEvidence = New-Object System.Security.Policy.Evidence
$replacementEvidence.AddHost((New-Object System.Security.Policy.Zone ([Security.SecurityZone]::MyComputer)))
$currentAppDomain = [System.Threading.Thread]::GetDomain()
$securityIdentityField = $currentAppDomain.GetType().GetField("_SecurityIdentity", ([System.Reflection.BindingFlags]::Instance -bOr [System.Reflection.BindingFlags]::NonPublic))
$securityIdentityField.SetValue($currentAppDomain,$replacementEvidence)