public static string CONNECTION_STRING = "";
public static string getconnection()
{
if (CONNECTION_STRING.Trim() == "")
{
CONNECTION_STRING = ConfigurationManager.ConnectionStrings["BloggingDatabase"].ConnectionString;
}
return CONNECTION_STRING;
}
}
Loading

Rijwan AnsariRank #82 · 24.2K reputationPosted Mar 4, 2022, 4:08 AM EST
Your code seems okay to get connection string value using function.
However, you can do in this way.
Sample:
private static string sqlConnectionString = string.Empty;
public static string GetConnectionString()
{
if (string.IsNullOrEmpty(sqlConnectionString))
{
sqlConnectionString = ConfigurationManager.ConnectionStrings["BloggingDatabase"].ConnectionString;
}
return sqlConnectionString;
}
Now, we use connection string to do database stuffs like adding, updating, deleting and querying records from database.
We execute queries (SQL query, Stored Procedures, Views and so on).
We can use in ADO.NET, Entity framework and Dapper for database operations.
You can find numerous blogs in google.
CRUD for ASP.NET using Entity framework, ADO.NET or Dapper.
Rajeesh MenothRank #118 · 18.4K reputationPosted Mar 6, 2022, 10:22 AM EST
Gajendra JangidRank #157 · 14.9K reputationPosted Mar 26, 2022, 10:45 PM EDT