Skip to content

dsf azure connection strings

travis edited this page Dec 17, 2020 · 1 revision

CONNECTION STRINGS

Once your database is created, you will need to connect that DB to your backend application, this can be made using connection strings.

CREATE THE CONNECTION STRING

Go to the Azure portal,select the App Service that you want to connect with the DB, to be able to establish this connection, both your DB and your App Service must be under the same resource group.

P.E

resource group

As we can see here, both the app service and the DB exist under the same resource group 'BW-dev'

Select your app service and go to 'settings > Configuration', scroll down looking for 'Connection strings' and click on "New connection string"

appservice

Put the name you want(we’ve put the name 'Context', this name will be used later in your appSettings.json) and select the DB type, and for fill the value box go to 'Home>SQL databases', click on the target DB and click on 'Show database connection strings', copy the value that appears there and paste it in the value box.

db
connection string

Paste the connection string in the 'value' box and click OK

Your connection string has been created.

USE THE CONNECTION STRING

Go to your project, open the file AppSettings.json and add the connection string

  "ConnectionStrings": {
    "Context": "Source=(localdb)\\MSSQLLocalDB;Initial Catalog=my-db;Integrated Security=True;"
  }

Context is the name that we choose for the connection string that we’ve created before and that value is only for local purposes.

When the application is deployed,the value for context will be replaced for the value of the connection string that we’ve created in the earlier steps, using this we avoid to put the user and the password into the code and we use them as secrets that will be replaced in the deployment.

Clone this wiki locally