Vbp
Vbp

Reputation: 1972

How to dispose ADODB.Command object in code migrated to VB.NET

We migrated some obsolete code from VB6 to VB.net and the previous code used ADODB for connecting to oracle. Below is how the code looks like

Dim cmd As New ADODB.Command

' stored procedures execution here

cmd = Nothing    // I want to dispose this cmd Object 

Nothing worked in VB6 but its creating lot of trouble with .NET there are open cursors on database. I know we should use the latest library and get rid of ADODB but for now is there a way I can dispose this object. I tried cmd.Dispose() but that did not worked.

Upvotes: 1

Views: 1955

Answers (2)

MarkJ
MarkJ

Reputation: 30408

Use Marshal.ReleaseComObject to tidy up COM objects. ADODDB is a COM library being used through COM Interop.

COM objects being used through COM-Interop will not have a Dispose method, but may still need to be tidied up manually. Contrast with "proper" .Net objects will likely have a Dispose method, or implement IDisposable.

Upvotes: 1

tom.dietrich
tom.dietrich

Reputation: 8347

In VB.net (or C# for that matter), classes which should be disposed should include a Dispose() Method. Classes which do not need to be disposed should not include a Dispose() method.

In your case, the Command instance may not need to be disposed, but I would wager that the Connection instance (which you haven't included in your example code, but I'm pretty sure you've got) does.

Upvotes: 0

Related Questions