14

I have an ARM template that (among others) creates a database on an Azure SQL server (which is also created by the template).

I need to output the database ADO.NET connectionstring.

Becuase I wasn't sure what the key is called, I am outputting the whole object: This is what I have on the JSON template file:

 "DatabaseConnectionString": {
      "type": "object",
      "value": "[listkeys(variables('dbResourceId'), variables('apiVersion'))]"
    }

The dbResourceId is 100% correct. If I output it instead, I get the correct ID and the apiVersion is the same I use when creating the DB. BUT, I get this error:

"code": "NotFound",

"message": "Resource not found for the segment 'listkeys'.",

The database is being created correctly

I have the exact same pattern/idea with a service bus and it works perfectly Help, this is killing me

Community
  • 1
  • 1
Mickey Cohen
  • 997
  • 7
  • 23
  • What does your dbResourceId variable look like? It should have the provider namespace at the beginning. I use this for helping return storage account keys for example: `[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2016-01-01')]` – Martyn C Nov 10 '16 at 17:17

1 Answers1

23

Well, looks like the connection string is simply not a property, this is why it cannot be returned with listkeys, it needs to be "calculated" using concat

"DatabaseConnectionString": {
  "type": "string",
  "value": "[concat('Server=tcp:',reference(variables('sqlserverName')).fullyQualifiedDomainName,',1433;Initial Catalog=',variables('dbName'),';Persist Security Info=False;User ID=',reference(variables('sqlserverName')).administratorLogin,';Password=',reference(variables('sqlserverName')).administratorLoginPassword,';MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;')]"
}
kamil-mrzyglod
  • 4,948
  • 1
  • 20
  • 29
Mickey Cohen
  • 997
  • 7
  • 23
  • 1
    I thought this is just a cleaver workaround but apparently this is the recommended way to get the connection string -> https://blogs.msdn.microsoft.com/azuresqldbsupport/2016/12/01/arm-template-outputs-for-azure-sql-database/ – Stoimen May 15 '19 at 15:44
  • 1
    @Stoimen The example from that site is identical to what's above. – JoeBrockhaus Jul 19 '19 at 16:17