public static string CONNECTION_STRING = "";
public static string getconnection()
{
if (CONNECTION_STRING.Trim() == "")
{
CONNECTION_STRING = ConfigurationManager.ConnectionStrings["BloggingDatabase"].ConnectionString;
}
return CONNECTION_STRING;
}
}
Loading
Gajendra JangidPosted Mar 27, 2022, 2:45 AM
Rajeesh MenothPosted Mar 6, 2022, 3:22 PM
Rijwan AnsariPosted Mar 4, 2022, 9:08 AM
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.