I am running a windows form locally and accessing an Azure SQL Server. But I get following error:
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:
Any pointers how to solve this?
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:
If you have done already, even though you are getting same error, once check below instructions:
Ensure you selected correct database while connecting.
Use latest version of visual studio.
Check your firewall rules allow your local machine to access the Azure SQL Server.
your credentials may refresh. You can try signing out and back into your Visual Studio to reinitialize the authentication session.
For more information you can refer to this.