Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

What is the best practice of adding connecting strings in asp.net core 2?

$
0
0

The following comes from web.config of an old asp.net Web Forms project. How do I add this to asp.net core 2? And then how I have accessed as I did before. Since "configurationManager" no longer exists in Core 2, how do I access it? I have an example of the old way I did it before below.

<connectionStrings><add name="strConnection" connectionString="Data Source=localhost;initial catalog=TestCatalogue;password=TestPassword;persist security info=True;user id=TestUser;packet size=4096" providerName="System.Data.SqlClient" />

And now, the way I accessed it before.

public static string strConnection;

strConnection = ConfigurationManager.ConnectionStrings["strConnection"].ConnectionString;


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>