{"record":{"id":"039796560f2bb053","repo":"microsoft/semantic-kernel","slug":"failed-to-check-if-database-self-database-name","errorCode":null,"errorMessage":"Failed to check if database '{self.database_name}' exists, with message {e}","messagePattern":"Failed to check if database '(.+?)' exists, with message (.+?)","errorType":"exception","errorClass":"VectorStoreOperationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/azure_cosmos_db.py","lineNumber":630,"sourceCode":"                cosmos_client = CosmosClient(str(cosmos_db_nosql_settings.url), credential=credential)\n\n        super().__init__(\n            cosmos_client=cosmos_client,\n            database_name=cosmos_db_nosql_settings.database_name,\n            cosmos_db_nosql_settings=cosmos_db_nosql_settings,\n            create_database=create_database,\n            **kwargs,\n        )\n\n    async def _does_database_exist(self) -> bool:\n        \"\"\"Checks if the database exists.\"\"\"\n        try:\n            await self.cosmos_client.get_database_client(self.database_name).read()\n            return True\n        except CosmosResourceNotFoundError:\n            return False\n        except Exception as e:\n            raise VectorStoreOperationException(\n                f\"Failed to check if database '{self.database_name}' exists, with message {e}\"\n            ) from e\n\n    async def _get_database_proxy(self, **kwargs) -> DatabaseProxy:\n        \"\"\"Gets the database proxy.\"\"\"\n        try:\n            if await self._does_database_exist():\n                return self.cosmos_client.get_database_client(self.database_name)\n\n            if self.create_database:\n                return await self.cosmos_client.create_database(self.database_name, **kwargs)\n            raise VectorStoreOperationException(f\"Database '{self.database_name}' does not exist.\")\n        except Exception as e:\n            raise VectorStoreOperationException(f\"Failed to get database proxy for '{id}'.\") from e\n\n    async def _get_container_proxy(self, container_name: str, **kwargs) -> ContainerProxy:\n        \"\"\"Gets the container proxy.\"\"\"\n        try:","sourceCodeStart":612,"sourceCodeEnd":648,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/azure_cosmos_db.py#L612-L648","documentation":"CosmosNoSqlStore._does_database_exist calls read() on the database client inside a try; a CosmosResourceNotFoundError maps to 'does not exist' (returns False), but any other exception is wrapped as VectorStoreOperationException. This is a runtime existence probe, so failures are typically transport/auth/permission related.","triggerScenarios":"Raised in _does_database_exist when cosmos_client.get_database_client(name).read() raises anything other than CosmosResourceNotFoundError. Causes include 401/403 (bad key or credential), throttling (429), network errors, firewall blocking the account, or a transient service error.","commonSituations":"Expired or rotated account key. Entra ID token expiry. Cosmos DB firewall / virtual network blocking the client. Throttling under high RU usage. Transient Azure service incidents.","solutions":["Read exc.__cause__ for the HTTP status: 401/403 -> fix key/credential; 429 -> back off / raise RU; network -> check firewall and connectivity.","Ensure the client host can reach the Cosmos account endpoint.","Retry transient failures with exponential backoff.","Verify the key/credential has access to the account."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    exists = await store._does_database_exist()\nexcept VectorStoreOperationException as e:\n    cause = e.__cause__\n    # 401/403 -> auth; 429 -> throttle/backoff; network -> connectivity\n","preventionTips":["Verify credentials have access to the account before runtime.","Configure Cosmos firewall / private endpoint to allow your client.","Retry with exponential backoff for transient HTTP errors."],"tags":["azure-cosmos-db","vector-store","runtime","network","authentication"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}