提供程序类型无法表示为 .NET 类型 OracleTypeException

Provider type could not be represented as a .NET type OracleTypeException

所以我有一个正在写入 oracle 数据库的应用程序,然后是另一个正在从同一数据库读取数据的应用程序。

当我到达行 Dim msgTime As TimeSpan = reader.GetTimeSpan(2) 时,出现异常(见下文)。

Oracle 文档说 INTERVAL DAY TO SECOND(这是我在数据库中存储数据的方式)可以转换为时间跨度(参见 here

有谁知道导致此异常的原因以及如何避免它?

谢谢。


异常:

Oracle.DataAccess.Types.OracleTypeException
Provider type could not be represented as a .NET type
   at Oracle.DataAccess.Types.TimeSpanConv.GetTimeSpan(OpoITLValCtx* pValCtx, OracleDbType oraType)
   at Oracle.DataAccess.Client.OracleDataReader.GetTimeSpan(Int32 i)
   at MyProgram.pollDatabase(Object sender, DoWorkEventArgs e)

写入数据库代码:

Dim oCommand As New OracleCommand("INSERT INTO LOGTABLE(PK, MID,MDATE,MTIME,STATUS,SEVERITY,ORIGQ,MESSAGE) VALUES (:pk, :msgid, :msgdate, :msgtime, :status, :severity, :message)")

oCommand.Parameters.Add("pk", OracleDbType.Varchar2, Guid.NewGuid().ToString().Substring(0, 12), ParameterDirection.Input)
oCommand.Parameters.Add("msgid", OracleDbType.Varchar2, message.MessageID, ParameterDirection.Input)
oCommand.Parameters.Add("msgdate", OracleDbType.Date, putDateSQL, ParameterDirection.Input)
oCommand.Parameters.Add("msgtime", OracleDbType.IntervalDS, putTimeSQL, ParameterDirection.Input)
oCommand.Parameters.Add("status", OracleDbType.Varchar2, "NEW", ParameterDirection.Input)
oCommand.Parameters.Add("severity", OracleDbType.Varchar2, messageSeverity, ParameterDirection.Input)
oCommand.Parameters.Add("message", OracleDbType.Clob, clob, ParameterDirection.Input)

读取数据库代码:

Dim conn As OracleConnection = New OracleConnection(oradb)
Dim oCommand As New OracleCommand("SELECT MID,MDATE,MTIME,STATUS,SEVERITY, ORIGQ, MESSAGE FROM LOGTABLE")
oCommand.CommandType = CommandType.Text
oCommand.Connection = conn
oCommand.Connection.Open()
Dim reader As Oracle.DataAccess.Client.OracleDataReader = oCommand.ExecuteReader()

If reader.HasRows Then

    While reader.Read()
        Try
            Dim messageID As String = reader.GetString(0)
            Dim msgDate As Date = reader.GetDateTime(1)
            If Not reader.IsDBNull(2) Then
                Dim msgTime As TimeSpan = reader.GetTimeSpan(2)
            End If
            Dim msgStatus As String = reader.GetString(3)
            Dim msgSeverity As String = reader.GetString(4)
            Dim msgOrigin As String = reader.GetString(5)
            Dim msgContent As String = reader.GetString(6)
        Catch ex As Exception
            Console.Out.WriteLineAsync(ex.Message)
        End Try
    End While

End If

我需要使用 Dim msgTimeInterval As Oracle.DataAccess.Types.OracleIntervalDS = reader.GetOracleIntervalDS(2) 而不是 Dim msgTime As TimeSpan = reader.GetTimeSpan(2)