8

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

3 Answers 3

8

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)

0

Edit - this answer is incorrect, see the link added in the original question for information about the real root cause.

It sounds like you're trying to connect with Windows Authentication and that's the cause of the failure (see this post as it seems to cover the error message you're getting). Change your connection string to use SQL Authentication or ensure that the user your powershell script is running as both has a domain-joined identity and has permissions to access the server. Basically, this is a SQL connection issue not a DAC issue.

2
  • Guess I removed too much information from the script. The connection string used is something like: "data source=servername;initial catalog=dbname;user id=deploy;password=p455w0rd;" If I understand it, that rules out the suggestion above. On more piece of information. I am connecting to the server via remote desktop connection using an account that is an administrator on the machine. Jan 10, 2014 at 8:49
  • Ah, thanks for clarifying. Dacpacs use OpenXML and the System.IO.Packaging APIs that are mentioned in that post you linked to, so perhaps following the steps mentioned there (using a separate AppDomain for this code) might work? I don't think there's a particular config option you could pass to the DacServices code to avoid this issue - it's a problem with its dependencies. Jan 10, 2014 at 18:43
0

It's been a few days now so I don't think a proper explanation will be forthcoming. I'll just post this as our workaround for anyone else who finds themselves in this situation. There is a Microsoft command line program SqlPackage.exe that is fairly easy to get hold of. It will silently deploy a dacpac, can be executed in Powershell and has parameters that support all the options that we need. If we use this instead of the Dac services assembly directly the domain problem does not arise.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.