Hi Team,
I need to connect to SQLServer and access the connection with C#.
In framework 4.8 I do it through the Web.Config file and access:
<connectionStrings>DefaultConnection … </connectionStrings>
And In c# I use
string cnString = ConfigurationManager.ConnectionStrings[“DefaultConnection”].ConnectionString;
How can I do it same in .Net6.0 ?
Hi Paul,
in my Wisej .Net 6.0 Project I put the connection strings in Default.json like this:
{
...
},
"settings": {
"dbConnectionLiveString": "Server=xxx;Database=xxx;user id=xxx;password=xxx;",
"dbConnectionTestString": "Server=xxx;Database=yyy;user id=xxx;password=xxx;"
}
}
Without further ado you can access the strings via Wisej.Web,Application class:
var dbConnectionString = Application.Configuration.Settings.dbConnectionLiveString;
Cheers, Gerhard
Please login first to submit.