0

I am trying to access the SQL connection string within .net core API project. My controller is using the following code to get it but the value of szDSN remains null.

string szDSN = Environment.GetEnvironmentVariable("DSNSQLConnectionString");

and I add it in my appsettings.json like this

"Values": {
    "DSNSQLConnectionString": "Data Source=(local);Initial Catalog=local;User Id=abc; Password=123"
  },

I used the same way of getting my SQL connection in .net core project of type functions and it worked fine.. But for some reason its not pulling the value from appsettting.json in API type of project. What am I doing incorrectly?

I am going to need to add many more configuration variables in this project which I will need in the controllers, not sure why Environment.GetEnvironmentVariable is not grabbing variable values from appsettings.json

2
  • 1
    Please let me know if the duplicate doesn't answer your question by tagging me in a comment (@john) Commented Jul 26, 2019 at 2:17
  • 1
    @John Thanks much for helping with the duplicate post link. I looked it up but it took me it didnt have clear answer for getting configuration values in a controller. However this link helped n case someone else has the same question. dzone.com/articles/… Commented Jul 29, 2019 at 23:18

1 Answer 1

1

As far as I know, Environment.GetEnvironmentVariable is for Windows Variables, not your projects.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.