If number of client is managable, then you store it in web config file and you need seperate dbContext implentation if everyones database is different. If same db design is same for all, you can store credentials in dictionary and dynamically prepare connection string run time and connect.
Here is an example for MSSQL (I assume you are not using EF)
Not need to store connectionstring in web config.
Prepare connection string. You can store user wise parameters in DB as well.
public string BuildConnectionString(string dataSource, string dbName, string userId, string password,
string persistSecurityInfo, string encrypt, string trustServerCertificate, string applicationIntent, string multiSubnetFailover)
{
return $"Data Source = {dataSource}; Initial Catalog = {dbName}; User ID = {userId}; Password = {password}; " +
$"Persist Security Info = {persistSecurityInfo}; Encrypt = {encrypt}; TrustServerCertificate = {trustServerCertificate};" +
$" ApplicationIntent = {applicationIntent}; MultiSubnetFailover ={multiSubnetFailover}";
}
DB Connection example:
void CheckDbConnection()
{
string connetionString = BuildConnectionString("WIN-50GP30FGO75", // or IP
"Demodb", "YourUserID", "YourPassword", "True", "False", "False",
"ReadWrite", "False");
string sql = "Select TutorialID,TutorialName from table1";
using (SqlConnection cnn = new SqlConnection(connetionString))
{
using (SqlCommand command = new SqlCommand(sql, cnn))
{
cnn.Open();
dataReader = sqlquery.ExecuteReader();
while (dataReader.Read())
{
Output = Output + dataReader.GetValue(0) + "-" +
dataReader.GetValue(1) + "</br>";
}
Console.Write(Output);
cnn.Close();
}
}
}