Hi

void Connect()
        {
            try
            {
                ST = new WebClient().DownloadString(first_adress + "servermodule/pass.php?sno=" + servno).ToString();
            }
            catch (System.Exception)
            {
                try
                {
                    ST = new WebClient().DownloadString(second_adress + "servermodule/pass.php?sno=" + servno).ToString();
                }
                catch (System.Exception)
                {
                    if (ST == "")
                    {
                        DateTime dt = DateTime.Now;
                        string c = string.Format("{0:d/M/yyyy HH:mm:ss}", dt);
                        label5.Text = "Error!" + " " + c;
                        error= true;
                    }
                    else
                    {
                        error = false;
                    }
                }

            }

        }

I'm using this code to connect to my server and take some values.If main server is not accessible then use back up server to take values.

So are there any better code to use?
I mean if I want to add another back up server what should i do?
I'm planning to use another try - catch block but there must be a better way.

Thank you for help.

Edited 7 Years Ago by Lethys: n/a

Instead of keeping variables first_address , second_address , and third_address , and so on, make an array of addresses and walk through the array until one succeeds or until they all have failed.

Comments
welcome
This question has already been answered. Start a new discussion instead.