My dear GURU's, I hope this meet you all in good health.
I am trying to get my connection string from appsetting.json but it returning 'null'
here are my appsetting.json
- {
- "Logging": {
- "LogLevel": {
- "Default": "Warning"
- }
- },
- "AllowedHosts": "*",
- "ConnectionString": {
- "IQCare": "Data Source=.\\SQLEXPRESS;Initial Catalog=patientdb;Integrated Security=True;",
- "NMRSConn": "Data Source=localhost;Port=3306; Database=openmrs; User Id=openmrs; Password=Admin123;"
- }
-
- }
my controller from where i want to access the connection string
-
-
-
-
- public IConfiguration Configuration { get; }
- public MigrateController(IConfiguration configuration)
- {
- Configuration = configuration;
- }
-
-
- #region ---- Create connection access method
- public SqlConnection GetSqlConn()
- {
- var connStr = Configuration["IQCare"];
- return new SqlConnection(connStr);
- }
-
- public MySqlConnection GetMySqlConn()
- {
- var connStr = Configuration["NMRSConn"];
- return new MySqlConnection(connStr);
- }
-
- using (SqlConnection connection = GetSqlConn())
- {
- connection.Open();
- var sql = "select idno, facid, fac_name, state_id from tbl_facility where state_id = '"+dd.Trim()+"'";
- using (SqlCommand cmd = new SqlCommand(sql, connection))
- {
- using (SqlDataReader reader = cmd.ExecuteReader())
- {
- if (reader.HasRows)
- {
-
- while (reader.Read())
- {
- connE.Facilities.Add(new Facility
- {
-
- FacilityName = reader["fac_name"].ToString(),
- DatimCode = reader["facid"].ToString(),
- State = reader["state_id"].ToString()
- });
- }
- }
- }
- }
- }
can anyone help me see why GetSqlConn() is returning 'null'
Thank you all