Unable to execute Cosmos DB queries using the Azure Cosmos DB extension in VS Code

鈴木 伽奈 0 Reputation points
2026-11-13T12:06:37.9466667+00:00

We would like to execute queries against Azure Cosmos DB from Visual Studio Code using the Azure Cosmos DB extension.

The affected user has been assigned the Cosmos DB Built-in Data Reader data-plane role for the target Cosmos DB account.

The user can successfully execute queries from Data Explorer in the Azure portal using the same account. However, when attempting to execute queries from the Azure Cosmos DB extension in Visual Studio Code, the query cannot be executed and the following errors are displayed:

2026-11-13 11:56:37.081 [info] fail Error: spawnSync cosmosdbshell ENOENT

2026-11-13 11:56:37.081 [info] while running "cosmosdbshell --version"

2026-11-13 11:56:37.081 [info] Cosmos DB Shell terminal context updated: closed

2026-11-13 11:56:37.082 [info] Cosmos DB Shell Extension: deactivated.

2026-11-13 11:56:37.082 [info] Error: Failed to process URI: Unable to find resource "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.DocumentDB/databaseAccounts/xxx".

Please ensure the resource exists and try again.

2026-11-13 11:57:39.233 [error] Failed to resolve connection for query editor: Cannot read properties of null (reading 'trim')

Could you please help us identify the cause of this issue?

Azure Cosmos DB
Azure Cosmos DB

An Azure NoSQL database service for app development.

0 comments No comments

1 answer

Sort by: Most helpful
  1. AI answer

    2026-11-13T12:07:00.0066667+00:00

    The primary cause is that the VS Code extension cannot find the Azure Cosmos DB Shell executable:

    • spawnSync cosmosdbshell ENOENT
    • while running "cosmosdbshell --version"

    ENOENT indicates the cosmosdbshell command is not available to the extension. When the shell is missing or not discoverable, the extension can fail to initialize correctly, which can then lead to follow-on errors such as failure to process the Cosmos DB resource URI and the query editor error Cannot read properties of null (reading 'trim').

    Recommended checks:

    1. Verify the VS Code extension is installed and visible.
      • Open Extensions with Ctrl+Shift+X.
      • Search for Cosmos DB.
      • Confirm the Azure Cosmos DB extension by Microsoft is installed.
    2. Verify the shell integration is available in VS Code.
      • Open the Command Palette with Ctrl+Shift+P.
      • Type Cosmos DB Shell.
      • Confirm Cosmos DB Shell commands appear.
    3. Check the local shell installation.
      • If installed via NuGet, run:
             cosmosdbshell --version
        
      • If installed as a binary, run:
             ./cosmosdbshell --version
        
      • If cosmosdbshell --version fails with command not found, ensure .NET SDK 10.0+ is installed, restart the terminal, and verify $HOME/.dotnet/tools is in PATH.
    4. Confirm VS Code version.
      • Go to Help > About.
      • Verify VS Code is 1.85 or later.
    5. Restart and, if needed, reinstall the extension.
      • Restart VS Code.
      • If the extension still does not load correctly, clear the extension cache and reinstall.
    6. After the shell is working, retry authentication in VS Code.
      • Open Command Palette.
      • Run Azure: Sign Out.
      • Run Azure: Sign In.
      • Complete browser authentication.
      • Re-select the correct subscription and resource group.
    7. If the resource tree is blank or the account cannot be resolved, verify the selected subscription and refresh the explorer.
      • In the Cosmos DB/Azure view, confirm the correct subscription is selected.
      • Press F5 or use the refresh icon.
      • Verify the Cosmos DB account exists and is accessible.

    The role assignment is unlikely to be the root cause here because the same account can query successfully in Azure portal Data Explorer. The logged failure points to a local VS Code extension/shell setup problem first, not a data-plane authorization problem.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    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.