【问题标题】:OleDbException (0x80004005): Not specified error?OleDbException (0x80004005):未指定错误?
【发布时间】:2010-06-25 01:20:01
【问题描述】:

我创建了一个按钮 (Next) 用于在名为 CHAPTERS 的表格中导航;

我的问题是按钮工作两次,有时是三次。之后我得到[未指定错误]。

这是我的代码:

Dim S As Integer = Integer.Parse(Request.QueryString("id"))
Dim RQ As String
Dim DR As OleDbDataReader
RQ = "SELECT ID_C FROM CHAPTRES"
DR = Connexion.lecture(RQ)
While DR.Read
    If DR.GetInt32(0) = S Then
            Exit While
        End If
    End While

    If DR.Read = True Then
        S = DR.GetInt32(0)
        Response.Redirect("Chapitre.aspx?id=" & S)
    Else   
        // End of records (stop reading)
    End If

谢谢。

UPDATES :

这是我的Connexion.vb 文件中的connecter 和lecture 函数:

Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient

Public Class Connexion

Public Shared Function conecter() As OleDbConnection
    Dim MyConnexion As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & System.AppDomain.CurrentDomain.BaseDirectory & "/Learning.mdb")
    MyConnexion.Open()
    Return MyConnexion
End Function

Public Shared Function lecture(ByVal requete As String) As OleDbDataReader
    Dim Mycommand As OleDbCommand = conecter().CreateCommand()
    Mycommand.CommandText = requete
    Dim myReader As OleDbDataReader = Mycommand.ExecuteReader()
    Return myReader

End Function

【问题讨论】:

    标签: c# asp.net vb.net oledb datareader


    【解决方案1】:

    您的问题可能是您没有关闭/处置您的 OleDbDataReader。 Response.Redirect 调用将您带到另一个页面,而无需关闭打开的数据阅读器。

    尝试将最后一段代码修改为:

    If DR.Read = True Then 
        S = DR.GetInt32(0) 
        DR.Close()
        DR.Dispose()
        Response.Redirect("Chapitre.aspx?id=" & S) 
    Else    
        // End of records (stop reading) 
    End If 
    

    更新:如果您提供更多信息显然会有所帮助,例如本示例中究竟是哪一行代码引发了异常。

    【讨论】:

    • @AZIRAR:您不必因为答案不正确而对答案投反对票。对于可能误导他人的严重不准确的答案,我通常会保留反对票。在您的情况下,您应该养成关闭数据读取器的习惯,无论这是否是您当前问题的原因。
    • 您是在尝试从 Access 数据库 (.mdb) 还是 Excel 文件 (.xls) 中读取数据?
    • 看起来此错误可能是由于连接处于打开状态而发生的。你的Connexion 对象是如何工作的?它是否保持开放连接?
    • @MusiGenesis this error occur as a result of a connection being left open 非常感谢。
    猜你喜欢
    • 1970-01-01
    • 2016-08-20
    • 2021-06-05
    • 2020-11-18
    • 2020-01-03
    • 1970-01-01
    • 2015-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多