Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output Azure SQL Database ConnectionString after template deployment

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

like image 912
Mickey Cohen Avatar asked Nov 10 '16 15:11

Mickey Cohen


People also ask

How do I find my Connectionstring?

Right-click on your connection and select "Properties". You will get the Properties window for your connection. Find the "Connection String" property and select the "connection string". So now your connection string is in your hands; you can use it anywhere you want.

How do I get Azure SQL server connection string?

Get ADO.NET connection information (optional - SQL Database only) Navigate to the database blade in the Azure portal and, under Settings, select Connection strings. Review the complete ADO.NET connection string. Copy the ADO.NET connection string if you intend to use it.


1 Answers

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;')]"
}
like image 85
Mickey Cohen Avatar answered Sep 22 '22 03:09

Mickey Cohen