I set a MySQL connection string with MVC database first as below:
<add name="wf_workflowEntities" connectionString="metadata=res://*/Models.MySql.Model1.csdl|res://*/Models.MySql.Model1.ssdl|res://*/Models.MySql.Model1.msl;provider=MySql.Data.MySqlClient;provider connection string="server=192.168.1.8;user id=test;password=abc.1234;CHARSET=utf8;database=wf_workflow"" providerName="System.Data.EntityClient" />
I want to replace some parameters of connection string if it was needed.for instance, for switching servers the IP of server must be set again(etc username,password).
I use this model for sending customized parameters:
public partial class BPMEngine
{
public string DBServer { get; set; }//ip server
public string DBName { get; set; }//database name
public string DBUserName { get; set; }//username
public string DBPass { get; set; }//password
}
and this is view:
@Html.TextBoxFor(model => model.DBServer, new { @class = "form-control1", placeholder = "ip server" })
@Html.TextBoxFor(model => model.DBName, new { @class = "form-control1", placeholder = "database name" })
@Html.TextBoxFor(model => model.DBUserName, new { @class = "form-control1", placeholder = "username" })
@Html.TextBoxFor(model => model.DBPass, new { @class = "form-control1", placeholder = "password" })
<button type="submit" class="btn btn-block btn-success" id="transfer">save</button>
But I don't know how can I change connection string's parameters at web.config via controller(or action result).
In fact, I don't know, what should I do in controller for this problem?