I am trying to deploy a DACPAC file using Azure Runbook Automation using the latest "Microsoft.SqlServer.Dac.dll" which is zipped and then uploaded as a module to Azure Automation Account. I can access this DLL file correctly. However, when I try to run the below code, I get an error -
Add-Type -Path "C:\Modules\User\Microsoft.SqlServer.Dac\Microsoft.SqlServer.Dac.dll"
$dacService = New-Object Microsoft.SqlServer.dac.dacservices("Server=tcp:xxxx.database.windows.net,1433;Initial Catalog=testdatabase;Persist Security Info=False;User ID=xxxxxx;Password=xxxxx@12345;")
$dacPackage = [Microsoft.SqlServer.Dac.DacPackage]::Load($env:TEMP + "\SQL.dacpac")
$dacService.deploy($dacPackage,"testdatabase",$true,$options,$null)
I am getting the following error on the 2nd line -
New-Object : Exception calling ".ctor" with "1" argument(s): "The type ?>initializer for 'Microsoft.SqlServer.Dac.DacServices' threw an exception." At >line:98 char:15 + ... acService = New-Object >Microsoft.SqlServer.dac.dacservices("Server=tc ... + >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : >InvalidOperation: (:) [New-Object], MethodInvocationException + >FullyQualifiedErrorId : >ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
Any idea what might be going wrong? The same code works fine when I execute on my Powershell locally. The DACPAC file is created with Azure SQL Database V12 as its target platform. Also, the DLL file is the latest one from SSMS 17.2.