无法在 VB.NET 中关闭 Sybase 数据库的 OledbDataReader
我似乎无法在读取数据后关闭 OledbDataReader 对象。 这是相关的代码 -
Dim conSyBase As New OleDb.OleDbConnection("Provider=Sybase.ASEOLEDBProvider.2;Server Name=xx.xx.xx.xx;Server Port Address=5000;Initial Catalog=xxxxxxxxxx;User ID=xxxxxxxx;Password=xxxxxxxxx;")
conSyBase.Open()
Dim cmdSyBase As New OleDb.OleDbCommand("MySQLStatement", conSyBase)
Dim drSyBase As OleDb.OleDbDataReader = cmdSyBase.ExecuteReader
Try
While drSyBase.Read
/*Do some stuff with the data here */
End While
Catch ex As Exception
NotifyError(ex, "Read failed.")
End Try
drSyBase.Close() /* CODE HANGS HERE */
conSyBase.Close()
drSyBase.Dispose()
cmdSyBase.Dispose()
conSyBase.Dispose()
控制台应用程序只是在我尝试关闭阅读器时挂起。 打开和关闭连接不是问题,因此有人对可能导致此问题的原因有任何想法吗?
I don't seem to be able to close the OledbDataReader object after reading data from it. Here is the relevant code -
Dim conSyBase As New OleDb.OleDbConnection("Provider=Sybase.ASEOLEDBProvider.2;Server Name=xx.xx.xx.xx;Server Port Address=5000;Initial Catalog=xxxxxxxxxx;User ID=xxxxxxxx;Password=xxxxxxxxx;")
conSyBase.Open()
Dim cmdSyBase As New OleDb.OleDbCommand("MySQLStatement", conSyBase)
Dim drSyBase As OleDb.OleDbDataReader = cmdSyBase.ExecuteReader
Try
While drSyBase.Read
/*Do some stuff with the data here */
End While
Catch ex As Exception
NotifyError(ex, "Read failed.")
End Try
drSyBase.Close() /* CODE HANGS HERE */
conSyBase.Close()
drSyBase.Dispose()
cmdSyBase.Dispose()
conSyBase.Dispose()
The console application just hangs at the point at which I try to close the reader. Opening and closing a connection is not a problem, therefore does anyone have any ideas for what may be causing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已经有一段时间没有使用 VB.NET 了,但在 C# 中处理此问题的最安全方法是使用“using”语句。
它就像一个隐式 try-catch,它确保在“使用”结束时关闭/取消并处置所有资源。
更新:找到一个关于在VB.NET 2.0中使用语句,希望有帮助。
It's been a while since I used VB.NET, but the most safe way to handle this in C# is to use a "using" statement.
It's like an implicit try-catch and it makes sure all resources are closed/cancelled and disposed when the "using" ends.
Update: Found a link about Using statement in VB.NET 2.0, hope it helps.
这是一个不太可能的方案,但请尝试将 .Close() 和 .Dispose() 行移到 Try 的 Final 块中。 像这样:
This is a long-shot, but try moving your .Close() and .Dispose() lines in a Finally block of the Try. Like this:
我找到了答案!
之前
在你需要调用Command对象的cancel方法
我相信这可能是Sybase数据库特有的
I found the answer!
Before
You need to call the cancel method of the Command object
I believe that this may be specific to Sybase databases