How to resolve "System.Data.Common: Format of the initialization string does not conform to specification starting at index 0." error?

So Yon Lee 40 Reputation points
2024-11-14T17:48:05.2566667+00:00

I'm following this exercise:

https://learn.microsoft.com/en-us/training/modules/automatic-update-of-a-webapp-using-azure-functions-and-signalr/3-exercise-analyze-limitations-of-polling-in-a-web-app

In the 'Run the server application' step, I encountered this error:

System.Private.CoreLib: Exception while executing function: Functions.setPrice. System.Data.Common: Format of the initialization string does not conform
to specification starting at index 0.

It seems like my connection string might be the issue. I ensured that I copied the sample local.settings.json correctly and replaced the values for AzureWebJobsStorage and COSMOSDB_CONNECTION_STRING as instructed, but I am still unable to resolve the error.

Any assistance would be greatly appreciated.

This question is related to the following Learning Module

Azure Azure Training
0 comments No comments
{count} votes

Accepted answer
  1. Ravali Bakaram 170 Reputation points Microsoft External Staff
    2024-11-15T07:57:17.7366667+00:00

    Hi So Yon Lee,

    Since the Microsoft Q&A community has a policy that the question author cannot accept their own answer. They can only accept answers by others, Summarized and posted the solution that you shared, request you to Accept the answer, it will benefit the community find the answers quickly.

    Scenario:

    You are encountering the error message: "System.Data.Common: Format of the initialization string does not conform to specification starting at index 0." This typically indicates an issue with the format of your connection string.

    Issue:

    While following the exercise to run the server application, it seems that the connection string for Azure Cosmos DB might be incorrectly formatted.

    Things Tried:

    You have copied the sample local.settings.json correctly and replaced the values for AzureWebJobsStorage and COSMOSDB_CONNECTION_STRING as instructed but are still facing the error.

    Solution shared by So Yon Lee

    Resolution:

    To resolve this issue, ensure that your COSMOSDB_CONNECTION_STRING is formatted correctly. It should adhere to the following structure:

    COSMOSDB_CONNECTION_STRING="AccountEndpoint=<your-cosmosdb-URI>;AccountKey=<your-account-key-here>"
    

    Make sure to replace <your-cosmosdb-URI> and <your-account-key-here> with the actual values provided in your Azure Cosmos DB account.
    Example of a correctly formatted local.settings.json:

    {
    "IsEncrypted": false,
    "Values": {
    "AzureWebJobsStorage": "<STORAGE_CONNECTION_STRING>",
    "FUNCTIONS_WORKER_RUNTIME": "node",
    "AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
    "COSMOSDB_CONNECTION_STRING": "AccountEndpoint=https://your-cosmosdb-uri;AccountKey=your-account-key;"
    },
    "Host": {
    "LocalHttpPort": 7071,
    "CORS": "http://localhost:3000",
      "CORSCredentials": true
      }
    }
    
    

    Ensure there are no extra spaces or characters in the connection string, as these can also lead to initialization errors.

     


1 additional answer

Sort by: Most helpful
  1. So Yon Lee 40 Reputation points
    2024-11-14T19:30:47.6733333+00:00

    I found the issue and fixed.

    In both ./setup-resources/.env and ./start/server/local.settings.json, cosmosDB connection string should follow this format.

    COSMOSDB_CONNECTION_STRING="AccountEndpoint=<your-cosmosdb-URI>;AccountKey=<your-account-key-here>"

    Hope it helps someone struggling with the same error.

    0 comments No comments

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.