• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

VB.net ADO exception when exiting

brandonb

Diamond Member
I've been trying to add asyncronous queries to my application, however, I'm running into trouble doing so.

I've used the ADO .net wrapper to do the query, and I've dimmed it withevents.

Imports ADODB

Public Class DB

Private WithEvents ADO As ADODB.Connection

Public Sub New()

ADO = New ADODB.Connection
ADO.ConnectionTimeout = 30
ADO.CursorLocation = 3

End Sub

Protected Overrides Sub Finalize()

ADO.Cancel()

Select Case ADO.State
Case ConnectionState.Open, ConnectionState.Fetching, ConnectionState.Executing, ConnectionState.Connecting
ADO.Close()
End Select

ADO = Nothing

MyBase.Finalize()
End Sub

However, ADO = nothing crashes when exiting. About the RCW being lost or something to that effect. I've read around the web that .net can't handle WithEvents very well so you have to kill the com object directly.

Try
intl_COUNT = System.Runtime.InteropServices.Marshal.ReleaseComObject(ADO)
While intl_COUNT > 0
intl_COUNT = System.Runtime.InteropServices.Marshal.ReleaseComObject(ADO)
End While
Catch ex As Exception
Finally
GC.Collect()
GC.WaitForPendingFinalizers()
End Try

ADO = nothing

But ADO = Nothing still crashes with a different error (and the examples on the web indicate you can do that safely after doing the ReleaseComObject routine)

Does anybody know of a safe way to do this?

I don't want to be forced into using syncronous queries, which works very well btw.
 
Back
Top