I want to create a global value inside asp net for getting SQL Server connection string.
Should I create a public read only string?
public static readonly string connectionString="myconnection string";
inside a class?
Or do I need to add a key value inside Web.Config?
<connectionStrings>
<add name="SqlDatabase"
connectionString="yourConnectionString"
providerName="System.Data.SqlClient" />
</connectionStrings>
And to use it inside get or post request
public string Get(int id)
{
var connectionString = WebConfigurationManager.ConnectionStrings["SqlDatabase "].ConnectionString;
return "connectionString";
}
This string will be used from many client request at same time.
web.config. You could create a static class with a static readonly public string property that is initialized in the static constructor of the class and reads in that value from the connection string once from theweb.config.