如何在迁移到VB.NET的代码中处理ADODB.Command对象 [英] How to dispose ADODB.Command object in code migrated to VB.NET
问题描述
我们将一些过时的代码从VB6迁移到了VB.net,并且先前的代码使用ADODB连接到oracle。下面是代码的样子
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
没什么
在VB6中工作,但是它对.NET造成了很多麻烦,因为数据库中存在打开的游标。我知道我们应该使用最新的库并摆脱ADODB,但目前有一种方法可以处置此对象。我尝试了 cmd.Dispose()
,但是没有用。
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.
推荐答案
使用 Marshal.ReleaseComObject 整理COM对象。 ADODDB是通过COM Interop使用的COM库。
Use Marshal.ReleaseComObject to tidy up COM objects. ADODDB is a COM library being used through COM Interop.
通过COM-Interop使用的COM对象将不具有 Dispose
方法,但可能仍需要手动整理。与适当的 .Net对象相反,Net对象可能具有 Dispose
方法,或实现 IDisposable
。
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
.
这篇关于如何在迁移到VB.NET的代码中处理ADODB.Command对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!