-1

I don't know how to loop through my local database and add the values to this string:

string credentials = @"server = 127.0.0.1;
user id = system; 
port = 3308; 
Password = 975315";

https://i.sstatic.net/Epjao.png

I kind of need something like this:

string credentials = @"server = IDindb;
user id = IDindb; 
port = Portindb; 
Password = Pwindb";


foreach(rowofdata in localdb)
{
        MySqlConnection con = new MySqlConnection(credentials);
        con.Open(); //Opens the connection
        MySqlCommand cmd = new MySqlCommand(sqlQuery, con); //Sends the 
query to "show slave status"

Create a new table in browser that shows if server is running or not.
}
1
  • 1
    I kind of need something like this: Yep, that looks like a reasonable approach. Why don't you try it? Commented Feb 11, 2019 at 12:17

1 Answer 1

0

This is quite a good homework assignment - It touches frontend, database, networking and middleware, and importantly it forces you to properly think through all the little decisions of what might go wrong, e.g.

  • what do you do when the server doesn't respond (write "server down into your html table)
  • how do you trap this without your own code failing.
  • What if the servers take a really long time to respond? Timeout?
  • Should you be doing this to each server in succession, or all at once, adding their responses into the table as you go?

What I'm saying is you should think about your overall solution some more before diving into the code.

To answer the question, assuming you have some code to connect to the local db and query the table, rowofdata will be a recordset, with each row populated per the row in your image.

Extract the server, user, password etc credentials from it:

var masterHost = rowofdata["Master_Host"].ToString();

and create the connection string inside the for-loop.

var credentials = $"server={masterHost};user id={userId}; port={portId}; Password={password}"; 

The Create new Table in browser part will depend on which platform/language you're writing in. And in any case shouldn't be done here, unless you're intent on mixing db access with html (@Razor? classic asp?).

Store the server / status values in a list (of server object, with status etc), then subsequently use them to populate the html. (Or build the html table and render that, and use ajax to request the status of each).

(unrelated - how do you plan on implementing the stop/start/fix button code?)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks its working! Everything is connected now, but how do i get the whole top part of the pic into a table row when i add a server? This is my code now: i.imgur.com/Ld4Bjsx.png
Depends how you have implemented the html rendering. I don't see any in there, but (guess) based on the method name - BindData() - you have a control of some sort and you're trying to bind data to it. Have a look at this stackoverflow.com/a/19603010/1818795

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.