我希望能够向该程序添加/删除更多服务器,我真的不知道该如何解决。您能提出一些建议,用c#在asp.net中执行此操作吗?
DataSet ds = new DataSet();
private DataTable dt;
string credentials = @"server = 127.0.0.1; user id = system; persistsecurityinfo = True; port = 3308; database = test1; Password = 975315"; //Server credentials
string sqlQuery = @"show slave status";
string sqlStop = @"stop slave;";
string sqlStart = @"start slave;";
public void BindData()
{
//Opens the connection and sends "show slave status" command.
MySqlConnection con = new MySqlConnection(credentials);
con.Open(); //Opens the connection
MySqlCommand cmd = new MySqlCommand(sqlQuery, con); //Sends the query to "show slave status"
MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
adp.Fill(ds); //Fill Dataset.
dt = ds.Tables[0]; //Then assign table to dt.
foreach (DataRow dataRow in dt.Rows) //Checks the server if it is running or not.
{
string value = dataRow.Field<string>("Slave_IO_Running"); //Looks for "Slave_IO_Running" status.
if (value == "Yes")
{
Label1.Text = "WORKING";
Label1.ForeColor = System.Drawing.Color.Green;
}
else
{
Label1.Text = "REPLICATION ERROR";
Label1.ForeColor = System.Drawing.Color.Red;
}
}
//Shows a view of the whole query
GridView1.DataSource = dt.DefaultView;
GridView1.DataBind();
}
protected void Button1_Click1(object sender, EventArgs e)
{
}
}