I want to know how to change automatically the connection string of my app so when I\'m working on it in my pc, it uses my local SQL Server and once I publish it then uses t
I decided to bypass the whole web.config and instead integrate a function that determines the connection string based off of the current machine it is running from. To set this up I had to set up my ApplicationDbContext() to gather the connection string from the function like so:
public ApplicationDbContext() : base(CFFunctions.GetCFConnection())
{
}
Note that my function is Static:
public static string GetCFConnection()
{
string Connection = "";
string Machine = System.Environment.MachineName.ToLower();
switch(Machine)
{
case "development":
Connection = @"Data Source=DEV_SRV;Initial Catalog=CeaseFire;Integrated Security=True";
break;
case "production":
Connection = @"Data Source=PRO_SRV;Initial Catalog=CeaseFire;Integrated Security=True";
break;
}
return Connection;
}