vb.net의 OLEDBDATAREADER를 SYBASE 데이터베이스로 닫을 수 없습니다
-
02-07-2019 - |
문제
데이터를 읽은 후 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()
콘솔 애플리케이션은 독자를 닫으려고하는 시점에 매달려 있습니다. 연결을 열고 닫는 것은 문제가되지 않으므로이 원인이 무엇인지에 대한 아이디어가 있습니까?
해결책
나는 대답을 찾았다!
전에
drSyBase.Close()
명령 개체의 취소 메소드를 호출해야합니다.
cmdSyBase.Cancel()
나는 이것이 Sybase 데이터베이스에만 국한 될 수 있다고 생각합니다.
다른 팁
이것은 장거리이지만, .close () 및 .dispose () 라인을 최종적으로 시도의 블록으로 이동하십시오. 이와 같이:
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.")
Finally
drSyBase.Close()
conSyBase.Close()
drSyBase.Dispose()
cmdSyBase.Dispose()
conSyBase.Dispose()
End Try
vb.net을 사용한 지 얼마되지 않았지만 C#에서 이것을 처리하는 가장 안전한 방법은 a를 사용하는 것입니다.사용" 성명.
그것은 비슷합니다 암시 적 시도-캐치 그리고 "사용"이 종료 될 때 모든 리소스가 닫히고 취소되고 배치되도록합니다.
using (OleDb.OleDbConnection connection = new OleDb.OleDbConnection(connectionString))
{
DoDataAccessStuff();
} // Your resource(s) are killed, disposed and all that
업데이트: 링크를 찾았습니다 vb.net 2.0의 명령문 사용, 그것이 도움이되기를 바랍니다.
Using 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;"), _
cmdSyBase As New OleDb.OleDbCommand("MySQLStatement", conSyBase)
conSyBase.Open()
Dim drSyBase As OleDb.OleDbDataReader = cmdSyBase.ExecuteReader
Try
While drSyBase.Read()
'...'
End While
Catch ex As Exception
NotifyError(ex, "Read failed.")
End Try
cmdSyBase.Cancel()
End Using
제휴하지 않습니다 StackOverflow