ConnectionState issue

  • Thread starter Thread starter William Ryan eMVP
  • Start date Start date
W

William Ryan eMVP

I'm seeing something weird and I must just be overlooking something. I have
a connection and I open it(connection is named 'cn'). I close it in my
execution block but I have it wrapped in a Try/Catch/Finally and in finally
I check if the connectionState <> ConnectionState.Closed - if it's not then
I call .Close. However, even though it successfully closes and the debugger
tells me it's closed in the If Statement, it still runs to Close. This
isn't a big deal in that it doesn't cause any problems but I've verified
that the connection is closed and I'm wondering what's up with that?



Finally

Debug.Assert(cn.State = ConnectionState.Closed)

'The assertion doesn't fail indicating that it's in fact close



If cn.State <> ConnectionState.Closed Then cn.Close()

If I put my cursor here (On cn.State) it indicates closed as well, but it
always calls Close anyway. Any ideas?

End Try




--

W.G. Ryan, eMVP

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
 
Hi William,

Why don't you put if statement in more lines and put a debug.writeline
inside:
If cn.State <> ConnectionState.Closed Then
Debug.WriteLine(cn.State)
cn.Close()
End If
 
Thanks Miha! BTW - everything was mailed and should be there any day ;-)

--

W.G. Ryan, eMVP

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
Miha Markic said:
Hi William,

Why don't you put if statement in more lines and put a debug.writeline
inside:
If cn.State <> ConnectionState.Closed Then
Debug.WriteLine(cn.State)
cn.Close()
End If

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com


William Ryan eMVP said:
I'm seeing something weird and I must just be overlooking something. I have
a connection and I open it(connection is named 'cn'). I close it in my
execution block but I have it wrapped in a Try/Catch/Finally and in finally
I check if the connectionState <> ConnectionState.Closed - if it's not then
I call .Close. However, even though it successfully closes and the debugger
tells me it's closed in the If Statement, it still runs to Close. This
isn't a big deal in that it doesn't cause any problems but I've verified
that the connection is closed and I'm wondering what's up with that?



Finally

Debug.Assert(cn.State = ConnectionState.Closed)

'The assertion doesn't fail indicating that it's in fact close



If cn.State <> ConnectionState.Closed Then cn.Close()

If I put my cursor here (On cn.State) it indicates closed as well, but it
always calls Close anyway. Any ideas?

End Try




--

W.G. Ryan, eMVP

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
 
Back
Top