TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abraham Olatubosun
NA
471
113.6k
IConfiguration not working
Dec 21 2019 3:55 PM
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
/*
* Create Dipendency Injection into the controller
* */
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
Reply
Answers (
1
)
Generalizing JSON serializer
Need search during infinite loading of data