sql server - C# SqlClient connection open in thread - SqlException not caught -


I implemented the function with the timeout parameter on SqlClient . This means, that connection.open () is in another thread and after the thread has started, I have passed the time. If the time had elapsed, the thread has been canceled and no one The connection has not been established.

This thing is that if I grow up time periodically, the default connection.open () timeout, throws open () SqlException , which is not caught in my hold (SqlException) block.

I am starting the process of connecting completely in the second thread:

  public zero connect () {thread connectTrad = new thread (waitoutout); ConnectThread.Start (); }  

Connecting the thread -> Timeout waits another thread to wait

  wait for public zeroTemplate () {connection = new SqlConnection ( ConnectString); Thread timestthread = new thread (open connection); TimeoutThread.Start (); Date time to leave time = date time.Now added mileyaseconds (timeout); While (datetime.now 

Exceptions are not opened after the default () default timeout:

  Private Zero openConnection () {try {connection.Open () }} Hold (SqlException ex) {// it is not caught at any time}}  

Thanks for any thoughts!

Has it not been caught or has it not been thrown? Thread. The start only determines the thread to run, but this does not mean that it will start immediately, that the code throws up to the time interval of the timetable, then the open connection connection starts and always the connection within the default timeout Is successful in opening.

--- Edit

In this case, you may try this:

  1. SqlException with exception and check that you have ThreadInterruptedException instead of

  2. connection = new SqlConnection (connectString ); After entering (and comment on the rest code), enter the contents of the Open Connection Method in your WaitartTown method and see that the exception is still not handled if it does not, then it is in the connect method Put it back and check again


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -