ODBC 连接:"The connection has been disabled"

ODBC connection: "The connection has been disabled"

我有一个名为 IPEOPLE 的 32 位 ODBC 连接器,我正在尝试使用 VB 进行连接。如果我打开 Access 并使用 ODBC 驱动器 IPEOPLE,它工作正常并且我能够看到同一用户下的数据。

在 VB 中,我遇到了这种错误:

A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.dll System.Transactions Critical: 0 : http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/UnhandledUnhandled exceptionNMIALERTS.vshost.exeSystem.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089The connection has been disabled. at System.Data.Odbc.OdbcConnection.ConnectionIsAlive(Exception innerException) at System.Data.Odbc.OdbcConnection.HandleErrorNoThrow(OdbcHandle hrHandle, RetCode retcode)

低于该错误:

ERROR [42000] [IPeople][Meditech ODBC Driver (5.0.0.36)][IPD 3.41] No fields in select --- End of inner exception stack trace ---

当我在 Access 中运行 SQL 时,它工作得很好。查询很好。很明显有一个字段被选中 (LIVE.NMISAA.QueueMessages.MessageID)。

而且我不太确定为什么。它没有被禁用。它可以通过 Access 正常使用。 Windows ODBC 数据源管理器上没有 "disabled" 指示符。 "NMIALERTS2" 是我机器上的用户 DSN。

代码:

    Dim myConnection As OdbcConnection = New OdbcConnection()
    myConnection.ConnectionString = "DSN=NMIALERTS2"

    Dim strQueryErxE1 As String = "SELECT LIVE.NMISAA.QueueMessages.MessageID FROM LIVE.NMISAA.QueueMessages " & _
        "WHERE LIVE.NMISAA.QueueMessages.QueueConnection = 'ERX_E_XO' and LIVE.NMISAA.QueueMessages.MessageID > '" & strPrevMsgID_ERX_E_XO & "'"

        Dim command1 As OdbcCommand
        Dim command2 As OdbcCommand

        If Active_ERX_E_XO = True Then
            command1 = New OdbcCommand(strQueryErxE1, connection) 'errors here
            command2 = New OdbcCommand(strQueryErxE2, connection)
        End If

有什么想法吗?

编辑:我已经从头开始将代码从 4000 行重建为最少 30 行以仅测试 ODBC,并且出现了完全相同的问题。这是我的全部代码:

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim myConnection As System.Data.Odbc.OdbcConnection = New System.Data.Odbc.OdbcConnection()
        myConnection.ConnectionString = "DSN=NMIALERTS2"

        Dim strQueryErxE1 As String = "SELECT LIVE.NMISAA.QueueMessages.MessageID FROM LIVE.NMISAA.QueueMessages " & _
    "WHERE LIVE.NMISAA.QueueMessages.QueueConnection = 'ERX_E_XO' and LIVE.NMISAA.QueueMessages.MessageID > '3000'"

        Dim command1 As System.Data.Odbc.OdbcCommand
        Dim strIIRADT1 As String = ""

        Using connection As New System.Data.Odbc.OdbcConnection(myConnection.ConnectionString)

            command1 = New System.Data.Odbc.OdbcCommand(strQueryErxE1, connection) 'error here

            connection.Open()

            Dim reader1 As System.Data.Odbc.OdbcDataReader

            reader1 = command1.ExecuteReader()

            If reader1.HasRows Then
                While reader1.Read
                    strIIRADT1 = reader1(0).ToString
                End While
            End If

        End Using

    End Sub
End Class

在深入研究 136 行错误后,我发现了这个埋藏的东西:

Database 'xyz' was not found in catalog 'LIVE' or your user does not have rights to the database or the database was not included in the DSN

基本上我错误地配置了 ODBC。 VB 没问题。这解决了更改此自定义驱动程序中的 ODBC 类型后的问题。