Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying a dacpac via Powershell caused error: "Unable to determine the identity of domain"

Has anyone else met a similar problem to the one described below?

I am having a problem deploying a SQL server 2012 dacpac database upgrade with Powershell. The details are as follows:

Its a dacpac file built for sql server 2012 and I'm trying to apply it to a sql server 2012 database via Powershell run from the command line when logged in as administrator.

Exception calling "Deploy" with "4" argument(s): "Unable to determine the identity of domain." At ... so.ps1:17 char:8 + $d.Deploy($dp, $TargetDatabase,$true,$DeployOptions)

The redacted script (logging and literals changed) is as follows:

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

Here is some supporting information:

  1. Dac framework version is 11.1
  2. The script throws the error when run on the command line:
    ie. Powershell -File databaseupgrade.ps1
    but not when run in the Powershell integrated script environment
  3. Similar scripts work from the command line for other dacpacs.

Research on the web might suggest that it might be something to do with the size of dacpac. The ones that work are all smaller than the one that does not and this link mentions a figure of 1.3mb which the file size of the failing dacpac just exceeds. If anyone can confirm that this is the problem can you also suggest a solution?

Update The following script exhibits the same behavior ie. works in PS Ide not from command line.

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

$f =   [System.IO.IsolatedStorage.IsolatedStorageFile]::GetMachineStoreForDomain();
Write-Host($f.AvailableFreeSpace);
like image 513
user3177696 Avatar asked Jan 09 '14 13:01

user3177696


People also ask

How do I unpack a Dacpac file?

Use one of these two methods to open the Unpack Data-tier Application dialog: Right-click the DAC package (. dacpac) file and select Unpack. Double-click the DAC package file.

What is a Dacpac file represent?

A file with . dacpac (stands for Data Tier AppliCation Package) extension is a database file, created with Microsoft SQL Server data tier application, that contains the database model for representation of database objects.

How does Dacpac deployment work?

The DAC package is in turn deployed to a test, staging or production database through an automated process or manually with a CLI or GUI tool. The . dacpac can be used to update a database with new or modified objects, to revert to a previous version of the database, or to provision an entirely new database.


1 Answers

I believe this issue here (at least in our case) is actually when the dacpac is working with a database that utilizes multiple filegroups. When doing the comparison for deployment my hypothesis is that it's utilizing the IsolatedStorage for the different files.

The link above was helpful, but it was not the entry as much as the last comment on that blog by Tim Lewis. I modified his code to work in native powershell. Putting this above the SMO assembly load should fix this issue:

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

like image 52
TheCodingHatter Avatar answered Oct 15 '22 11:10

TheCodingHatter