Issue creating a database at run (with EF) time with Managed Identity (not user/pass)

Sturla Þorvaldsson 176 Reputation points
2023-03-02T12:28:06.14+00:00

When we are running EF Core´s MigrateAsync() command with a connection string that has Active Directory Managed Identity in it, it fails when the database doesn't already exist.

We have this EF Core github issue where Arthur Vickers mentions that maybe you guys would have some information regarding this issue and if there was any special pattern you would recommend us using?

Hope to hear from you.

Azure SQL Database
Developer technologies | .NET | Other
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

1 answer

Sort by: Most helpful
  1. SSingh-MSFT 16,461 Reputation points Moderator
    2023-03-07T07:16:25.5+00:00

    Hi @Anonymous ,

    Welcome to Microsoft Q&A forum and thanks for using Azure services.

    As I understand from the GitHub link, you are getting "Login failed for user '<token-identified principal>" when creating database in migration (at runtime) while creation of DB with Managed Identity.

    In order to troubleshoot this issue, I would suggest first you need to make your SQL database AAD-enabled. Then you can create a user for your Managed Identity like this:

    CREATE USER [<identity-name>] FROM EXTERNAL PROVIDER;
    

    After this, assign permissions to that user as needed.

    Hope this helps. Please let us know if this works well and your inputs.

    Also, added C# tags so that the team also could share inputs if related to EF side.

    Thank you.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.