Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. 2 server

2 server

Scheduled Pinned Locked Moved C#
sysadmintutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aarontan
    wrote on last edited by
    #1

    Hi, I have an application which will connect to server A. However if server A fails...it should try to connect to server B. I have no idea how to go about implementing this. Any suggestions? ;)

    E 1 Reply Last reply
    0
    • A aarontan

      Hi, I have an application which will connect to server A. However if server A fails...it should try to connect to server B. I have no idea how to go about implementing this. Any suggestions? ;)

      E Offline
      E Offline
      ehuysamer
      wrote on last edited by
      #2

      What type of connection is this? Database? File share? Custom protocol? Start by putting all of your communication-related code into a separate class (or at least identifying which classes you use fits this description): should specific exceptions get thrown, you simply reinstantiate or reconfigure the class with different parameters (telling it to use server B). In the case of a database connection, as an example, you would change the connection string. This outlines the structure of a solution, but without more information I can't really help you.

      A 1 Reply Last reply
      0
      • E ehuysamer

        What type of connection is this? Database? File share? Custom protocol? Start by putting all of your communication-related code into a separate class (or at least identifying which classes you use fits this description): should specific exceptions get thrown, you simply reinstantiate or reconfigure the class with different parameters (telling it to use server B). In the case of a database connection, as an example, you would change the connection string. This outlines the structure of a solution, but without more information I can't really help you.

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        Hi, Tks for the reply. The connection is a database one. I had guess changing the connection string. However does connection lost or no connection exceptions come with common error strings. I guessing using this. try { str1 = db1; conn.ConnectionString = str1' conn.open(); } catch(Exception msg) { if(msg.Message.ToString()=="No Connection") { try {str1 = db2; conn.ConnectionString = str1; conn.Open(); } catch(Exception msg1) { MessageBox.Show("Total Connection Lost"); } } } Something like these? :~

        E 1 Reply Last reply
        0
        • A Anonymous

          Hi, Tks for the reply. The connection is a database one. I had guess changing the connection string. However does connection lost or no connection exceptions come with common error strings. I guessing using this. try { str1 = db1; conn.ConnectionString = str1' conn.open(); } catch(Exception msg) { if(msg.Message.ToString()=="No Connection") { try {str1 = db2; conn.ConnectionString = str1; conn.Open(); } catch(Exception msg1) { MessageBox.Show("Total Connection Lost"); } } } Something like these? :~

          E Offline
          E Offline
          ehuysamer
          wrote on last edited by
          #4

          Try: catch (SqlException ex). You can get far more from exceptions than that: Put a breakpoint on your MessageBox.Show, then quick-view the exception when the code gets there. You'll get a lot of info from there, including the actual sub-type of the exception that got thrown.

          A 1 Reply Last reply
          0
          • E ehuysamer

            Try: catch (SqlException ex). You can get far more from exceptions than that: Put a breakpoint on your MessageBox.Show, then quick-view the exception when the code gets there. You'll get a lot of info from there, including the actual sub-type of the exception that got thrown.

            A Offline
            A Offline
            aarontan
            wrote on last edited by
            #5

            tks for the reply... ok i tried that...I'm guessing i could use the number property to specify the error that i need to process..Also, there's one thing that puzzle me. There is a ConnectionState.Broken...when will this state occur? i tried have a connection open..then pluck off the cable..so i thought this is suppose to be connection broken. However the state of the connection is still open. Is there anything that i can refer to as to detect a break in connection from an open connect?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups