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.

Recommended Answers

All 3 Replies

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.

commented: welcome +7

oh my friend, you are back, i have missed you so much..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.