0

我知道这是非常基本的,我已经这样做了数百次。但是,出于某种奇怪的原因,我在数据库上执行了这个命令,当它试图从结果中读取一列时它失败了。如果我在以相同凭据登录的 SQL Plus 中执行此语句,则选择行(表有 1 行)就好了。任何想法我做错了什么?我尝试按名称、索引以及任何列访问列——它们都没有提供任何数据。我试过没有 .NextResult() (以防万一),同样的例外。

'...
' Determine if this database is Multisite enabled
Dim multisiteCmd As OleDbCommand = DbConnection.CreateCommand
multisiteCmd.CommandText = "SELECT * FROM TDM_DB_VERSION;"
Dim dbVersionReader As OleDbDataReader = multisiteCmd.ExecuteReader()
If dbVersionReader.HasRows Then
    dbVersionReader.NextResult()
    'If a ReplicaID was generated for the Database ID, then this is part of a
    'multisite implementation
    'Dim dbRepID As String = dbVersionReader("DB_REPLICID")
    Dim dbRepID As String = dbVersionReader(9)
    PluginSettings.UseMultisite = False
    If Not dbRepID Is Nothing Then
        If dbRepID.Length > 0 Then
            PluginSettings.UseMultisite = True
            PluginSettings.MultisiteReplicaId = dbRepID
        End If
    End If
End If
dbVersionReader.Close()

从这些立即命令可以看出,连接是打开的:

? DbConnection.Provider“OraOLEDB.Oracle”?DbConnection.State 打开 {1}

4

1 回答 1

1

NextResult()适用于具有多个结果集的语句。例如,如果您发送了这样的命令:

"SELECT * FROM TDM_DB_VERSION;SELECT * FROM dual;"

请注意,那里有两个查询。您可以通过对数据库的一次调用和一个 OleDbDataReader 来处理它们,NextResult() 是您执行此操作的一部分。

你想要的是这样的:

Dim multisiteCmd As OleDbCommand = DbConnection.CreateCommand
multisiteCmd.CommandText = "SELECT * FROM TDM_DB_VERSION;"
Dim dbVersionReader As OleDbDataReader = multisiteCmd.ExecuteReader()
If dbVersionReader.Read() Then
    'If a ReplicaID was generated for the Database ID, then this is part of a
    'multisite implementation
    'Dim dbRepID As String = dbVersionReader("DB_REPLICID")
    Dim dbRepID As String = dbVersionReader(9)
    PluginSettings.UseMultisite = False
    If Not dbRepID Is Nothing Then ' Do you mean check for DbNull here? "Nothing" is not the same thing
        If dbRepID.Length > 0 Then
            PluginSettings.UseMultisite = True
            PluginSettings.MultisiteReplicaId = dbRepID
        End If
    End If
End If
dbVersionReader.Close()
于 2014-09-05T15:57:53.020 回答