Connect to SQLServer and read connectionStrings in .NET 6.0 ?


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 ?


  • You must to post comments

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

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.