2 server
-
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? ;)
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.
-
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.
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? :~
-
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? :~
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.
-
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.
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?