Mike Miller
Mike Miller

Reputation: 213

Token retrieval failed with an error In Azure Data Studio

Using the latest Azure Data Studio Version: 1.32.0

Attempting to access a database using Azure Active Directory MFA and am getting the error:

Token retrieval failed with an error. Open developer tools to view the error

How can I resolve?

Connection type: Microsoft SQL Server
Authentication type: Azure Active Directory - Universal with MFA support

The server, account, and database fields are all populated with their respective necessary information.

A browser window pops up asking for username/password, which I enter valid credentials for, followed by the authentication being confirmed in the browser that follows, accompanied by instructions to close the browser window. Azure Data Studio then has the error displayed as mentioned above.

Upvotes: 20

Views: 30242

Answers (5)

agbalagbi
agbalagbi

Reputation: 1

Clear Cache works for me

Clear at the search area on ADS.

Upvotes: 0

ΩmegaMan
ΩmegaMan

Reputation: 31721

You have cached stale credentials.

Select the credentials in the Accounts section, delete them and then add fresh credentials.

Azure Data Studio Accounts Section

Upvotes: 17

Alfred Luu
Alfred Luu

Reputation: 2026

For MacOS user, please find /Users/{your_username}/Library/Application Support/azuredatastudio/Azure Account and remove it.

There is sometimes bug even download latest version but can't work, so I would recommend remove azuredatastudio for sure.

Upvotes: 0

philipnye
philipnye

Reputation: 695

If you open the Command Palette - Ctrl + Shift + P on Windows - one of the options is Azure Accounts: Clear Azure Accounts Token Cache. After applying this you'll be prompted to reload ADS.

You should then be invited to refresh your account credentials when you attempt to create a connection. If you're not, run Azure: Refresh All Accounts from the Command Palette and try creating the connection again.

Explanation

As mentioned by @JayakrishnaGunnam-MT in their answer, the problem seems to be to do with cached tokens. Running the first command deletes azureTokenCache_azure_publicCloud and azureTokenCacheMsal-azure_publicCloud from C:\Users\{UserNameHere}\AppData\Roaming\azuredatastudio\Azure Accounts without you needing to do it manually.

Upvotes: 18

JayakrishnaGunnam-MT
JayakrishnaGunnam-MT

Reputation: 1876

Problem seems to be with a cached token. try to delete the token from here C:\Users{UserNameHere}\AppData\Roaming\azuredatastudio\Azure Accounts and try to re authenticate.

Upvotes: 58

Related Questions