Unable to delete containers as one of the container name contains &

Srinu Tamada 45 Reputation points
2025-04-14T10:22:43.7833333+00:00

In Azure cosmos database, I created a container name with &. I didn't realize that it would create a problem. This container name passed from dev environment to production environment. Now I want to get rid of this container as I am not using. But from UI or CLI, I am not able to do so. I am not able to create a new container or delete existing one. Even I am not able to create new database with in the same cosmos database account.

How can I address this issue? My container name is: T&CStore

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,843 questions
{count} votes

Accepted answer
  1. Vijayalaxmi Kattimani 2,225 Reputation points Microsoft External Staff
    2025-04-14T11:41:28.28+00:00

    Hi Srinu Tamada,

    Greetings!

    We apologize for the inconvenience caused.

    We would like to inform you that, special characters like & in container names can cause some problems in Azure Cosmos DB, especially when using the Portal, CLI, or SDKs that don't properly encode or escape them. The name T&CStore is technically not a recommended format, and it's likely breaking API calls under the hood due to the unescaped ampersand.

    Since you are now stuck not only being unable to delete the container but also unable to create new containers or databases, it's likely the account itself is choking on that invalid name.

    Here are some steps and solutions that might help you resolve this issue:

    Method 1: You can use the Azure Cosmos DB SDK to delete the container. Using a language SDK (like Python, Node.js, or C#), you can bypass UI/CLI and ensure proper escaping. Here's an example using the Python.

    from azure.cosmos import CosmosClient
     
    endpoint = "https://<your-account>.documents.azure.com:443/"
    key = "<your-primary-key>"
    database_name = "<your-db-name>"
    container_name = "T&CStore"
     
    client = CosmosClient(endpoint, key)
    database = client.get_database_client(database_name)
     
    # Try deleting container
    try:
        container = database.get_container_client(container_name)
        container.delete_container()
        print(f"Deleted container: {container_name}")
    except Exception as e:
        print("Error deleting container:", e)
    

    You might need to URL-encode the name (T%26CStore) depending on the SDK and whether it escapes the name properly. Try both ways.

    Method 2: To delete a container use Azure Resource Explorer, do the following:

    1. Go to https://resources.azure.com/
    2. Navigate to your Cosmos DB resource.
    3. Carefully drill down into the containers node of your DB.
    4. See if the container is listed — sometimes you can issue a DELETE directly from the JSON view here.

    Note: Be extremely cautious — this tool gives you raw access and can break things.

    If the above methods do not work, you can try using the Azure CLI with the resource ID of the container:

    az cosmosdb sql container delete --account-name  --database-name  --name "T&CStore"
    

    Please refer this document: https://learn.microsoft.com/en-us/cli/azure/cosmosdb/sql/container?view=azure-cli-latest#az-cosmosdb-sql-container-delete

    I hope this information helps. If the issue still persists, please provide the server details via private message as it will help us conduct a more thorough investigation.

    I hope this information helps. Please do let us know if you have any further queries. If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.