0

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.

Pranav Jituri
  • 823
  • 1
  • 11
  • 25
  • I think that your connection string is wrong....it should be something like `$dacServices = New-Object Microsoft.SqlServer.Dac.DacServices ("data source=" + $tagetServer + ";Database=" + $databaseName + "; Trusted_connection=true")` – Hackerman Aug 16 '17 at 20:03
  • https://stackoverflow.com/questions/31348925/how-to-capture-dacsevices-deploy-output – Hackerman Aug 16 '17 at 20:06
  • @Hackerman - Nope. Still the same error. Changing the connection string shouldn't matter because like I said, the same code works fine on local Powershell ISE. – Pranav Jituri Aug 16 '17 at 20:12
  • So, running the script on your local server, and pointing to your azure database, runs fine... – Hackerman Aug 16 '17 at 20:22
  • Yep. Only when I copy paste the code to Azure runbook, it is giving me the above error. – Pranav Jituri Aug 16 '17 at 20:23
  • Maybe related https://stackoverflow.com/questions/24269005/microsoft-dacservices-powershell-error-on-constructor-when-calling-new-object – Hackerman Aug 16 '17 at 20:25
  • @Hackerman - I have already searched around. Only then I have created this issue. It is weird because same code is working fine locally. – Pranav Jituri Aug 16 '17 at 20:30

0 Answers0