Search code examples
entity-framework-6azure-sql-databaseazure-web-app-serviceazure-active-directoryadal

Connect to Azure SQL using Azure Active Directory from an Azure Website?


A have an Azure Website running which connects to an Azure SQL through Entity Framework 6. Everything runs and I'm using standard username/password (sql login) to connect.

Now, I would like to switch over to using AAD for authenticating to sql. I already have an AD Application set up for the website.

My question is:

  1. How do I connect with my cert or clientid/clientSecret?
  2. How do I ensure that the SqlAzureExecutionStrategy is still in function

Any guidance is much appreciated Thanks!


Solution

  • There are three ways connecting to SQL database by using Azure Active Directory authentication.

    1. Connecting using integrated (Windows) authentication
    2. Connecting with an Azure AD principal name and a password
    3. Connecting with an Azure AD token

    More detail about the Azure AD authentication for the Azure SQL database, you can refer here.

    And if you were trying the config the connecting with access token the code sample provided by this blog is helpful. Also it is helpful to familiar with to authenticate with Azure AD with the client credential flow using the certificate from this link.

    And based on my understanding, the connection string you used doesn't effect the Connection Resiliency feature which provided by the Entity Framework.