微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

有没有其他人遇到类似的问题,如下所述?

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

原文地址:https://www.jb51.cc/mssql/78638.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐