Search code examples
sql-servervisual-studio-codeazure-managed-database

Why can't I re-authenticate (MFA with mssql extension for VS Code)?


Here's an example of a connection configuration that has stopped working (it's for connecting to an Azure managed database):

{
  "server": "sqldb.12345abcde.database.windows.net",
  "database": "sqldb01",
  "authenticationType": "AzureMFA",
  "profileName": "sqldb01",
  "azureAccountToken": "",
  "expiresOn": 1648022420,
  "email": "[email protected]",
  "accountId": "aaaaaaaa-0000-bbbb-1111-cccccc222222"
}

When I try to connect, VS Code displays a dialog saying mssql: Credential Error: Account credentials have expired. Please re-authenticate. and another saying mssql: undefined:

VS Code dialog screenshot

After clicking the refresh credentials button, the linked page fails to resolve in my browser, showing ERR_CONNECTION_REFUSED:

ERR_CONNECTION_REFUSED browser screenshot

When I reinstall the plugin, remove my connection definitions from settings.json and attempt to create a new connection, the browser page resolves correctly and allows me to authenticate, but it has no effect in VS Code.

I'm able use the same connection details in Azure Data Studio to connect successfully.


Solution

  • I resolved this by deleting the contents of this folder (Mac): ~/Library/Application Support/vscode-mssql/AAD.

    I believe the equivalent on Windows would be something like C:\Users\{username}\AppData\Roaming\vscode-mssql\Azure Accounts.