加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql-server – 通过Powershell部署dacpac导致错误:“无法确定域

发布时间:2020-12-12 06:34:43 所属栏目:MsSql教程 来源:网络整理
导读:有没有其他人遇到类似的问题,如下所述? 我在使用Powershell部署SQL Server 2012 dacpac数据库升级时遇到问题.详情如下所示: 它是为sql server 2012构建的dacpac文件,当我以管理员身份登录时,我试图通过Powershell从命令行运行它来应用于sql server 2012数据
有没有其他人遇到类似的问题,如下所述?

我在使用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 Server110DACbinMicrosoft.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,$DeployOptions)

以下是一些支持信息:

> Dac框架版本是11.1
>在命令行上运行时,脚本会引发错误:
即. Powershell -File databaseupgrade.ps1
但不是在Powershell集成脚本环境中运行时
>类似的脚本可以在命令行中为其他dacpac工作.

对网络的研究可能表明它可能与达卡的大小有关.工作的那些都小于没有的那个,this link提到了一个1.3mb的数字,失败的dacpac的文件大小刚刚超过.如果有人可以确认这是问题,你还可以建议一个解决方案吗?

更新
以下脚本表现出相同的行为即.在PS Ide中工作,而不是从命令行.

[Reflection.Assembly]::LoadWithPartialName("System.IO.IsolatedStorage")

$f =   [System.IO.IsolatedStorage.IsolatedStorageFile]::GetMachineStoreForDomain();
Write-Host($f.AvailableFreeSpace);

解决方法

我相信这个问题(至少在我们的例子中)实际上是当dacpac使用一个利用多个文件组的数据库时.在进行部署比较时,我的假设是它将IsolatedStorage用于不同的文件.

link above很有帮助,但它不像Tim Lewis那样在博客上的最后评论那么多.我修改了他的代码以在原生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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读