Question

I am currently rewriting my team's database deployment Powershell script to use DACFx 3.0 API instead of 2.0. I've managed to get the DACPAC upgrade to work successfully, using the new Microsoft.SqlServer.Dac.DacServices controller class.

The only problem that remains is: how can I grab the current DACPAC version number off an existing database?

As part of our deployment script, we're comparing this to the DACPAC version that we are upgrading to, to determine whether a deployment is necessary. This is also used to decide whether to run the database-related tests, so this way we cut down a significant amount of time on our builds.

The old DacFx2.0 API lives in the Microsoft.SqlServer.Management.Dac namespace, so in the old Powershell script we simply created a DacStore object from the database connection and get the Version property off it:

OUR OLD POWERSHELL SCRIPT

$dacStore = New-Object Microsoft.SqlServer.Management.Dac.DacStore($serverConnection)
Write-Host "The following data-tier applications (instances) exist in the DAC store:"
foreach($dacInstance in $dacStore.DacInstances) 
{
    Write-Host Instance Name: $dacInstance.Name
    Write-Host DAC Type Application Name: $dacInstance.Type.Name
    Write-Host DAC Type Version: $dacInstance.Type.Version <--- **** this is what I need ****
}
...

The issue now in 3.0, the API lives in the Microsoft.SqlServer.Dac namespace, and "Instead of using the DacStore and DacExtractionUnit classes from previous versions, most everything has been refactored into the all-new DacServices controller class. (src)"

I haven't been able to find an equivalent of DacStore in the DacServices class yet, so as of right now I don't know how to retrieve the current DAC version. I've tried searching through MSDN documentations but all their Powershell sections still referenced the old DACFx2.0 API. (example: here).

If anyone could help me that would be greatly appreciated. Thanks!

Was it helpful?

Solution

Just got a reply from MSFT:

The Dac 3.0 API doesn't have this capability as you've discovered. Use T-SQL to select this data directly from dbo.sysdac_instances.

It seems like it is in fact the only way: http://msdn.microsoft.com/en-us/library/ee240830.aspx So I'll query off that view for now, although I'd really love to see it brought into the DACFx API at some point. Note that the view dbo.sysdac_instances is in the masters database, as msdb does not exist in SQL Azure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top