EF Core Connection to Azure SQL with Managed Identity

前端 未结 4 1297
日久生厌
日久生厌 2020-12-28 13:35

I am using EF Core to connect to a Azure SQL Database deployed to Azure App Services. I am using an access token (obtained via the Managed Identities) to connect to Azure SQ

4条回答
  •  孤独总比滥情好
    2020-12-28 14:28

    Is this a right way to do it or will it have issues with performance?

    That is the right way. OnConfiguring is called for each new DbContext, so assuming you don't have any long-lived DbContext instances, this is the right pattern.

    Do I need to worry about token expiration? I am not caching the token as of now.

    AzureServiceTokenProvider takes care of caching.

    Does EF Core has any better way to handle this?

    Setting the SqlConnection.AccessToken is currently the only way of using AAD Auth in SqlClient for .NET Core.

提交回复
热议问题