azurevisual-studioazure-managed-identity

Visual Studio and managed identity


I am running a windows form locally and accessing an Azure SQL Server. But I get following error:

enter image description here

I can access the SQL server locally from studio management. I am using PIM and I noticed when I elevate my self I need to restart SQL Studio Management. I wonder if it can be something similar. Yesterday it worked fine after 4-5 minutes, today after 45 mins I still get the error.

This is my connection string:

Server=sql-xx-prd.database.windows.net;Database=db-xx-prd;Authentication=Active Directory Default;Encrypt=True;Timeout=90"

And I setup Visual Studio with:

enter image description here

Any pointers how to solve this?


Solution

  • ConnectionError: Login failed for user 'token-identified-principal'.

    According to the MS document, if the user is not valid in the database or if the user is not the AAD Server Admin, you may get the above error while connecting to the database.

    Create the user in the database by logging in to the SQL Server with an administrator account, adding a user to the database, and assigning a role to the user:

    create user [AD user] from external provider;
    alter role db_datareader add member [AD user];
    alter role db_datawriter add member [AD user];
    

    Alternatively, you can set the AD user as sql server admin as shown below:

    enter image description here

    If you have done already, even though you are getting same error, once check below instructions:

    For more information you can refer to this.