2

I am working on an asp.net core web api project and its hosted on azure app service. What I'm trying is to put my cosmos db connection string in app service connection string. I added a document db type connection string but when I'm calling it, it wont get read.

enter image description here

I tried this,

CosmosDBAccountPrimaryKey = _configuration.GetConnectionString("DOCDBCONNSTR_COSMOSDBCONNSTR");

this also,

CosmosDBAccountPrimaryKey = _configuration.GetConnectionString("COSMOSDBCONNSTR");

But none worked. For just checking i tried to put the connection string in app setting variables and tried this,

CosmosDBAccountPrimaryKey = _configuration["COSMOSDBCONNSTR"];

This worked but when I'm calling from connection string, its not working.

5
  • Refer this SOThread for the same issue. Commented Mar 15, 2024 at 7:11
  • You need to add .AddEnvironmentVariables and retrieve the key. Commented Mar 15, 2024 at 7:12
  • 1
    I just changed the connection string type to custom and it worked before it was set to document Commented Mar 15, 2024 at 7:17
  • Irrespective of Type you can retrieve it as mentioned in the above link Commented Mar 15, 2024 at 7:18
  • @wasihyder It's great to hear that you were able to resolve your issue. Could you please document your solution in an answer? It would provide clarity for those encountering similar technical challenges within the community. Commented Mar 18, 2024 at 11:55

1 Answer 1

2

The issue was Type of connection string when creating it in app service. I was setting its type to Document DB which was not working. But when I set it up to Custom then it started working

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.