在ODBCDataReader的GetValues期间出现空异常

时间:2010-11-18 10:44:51

标签: .net .net-2.0 odbc

我似乎有幸遇到funniest problems while deploying my software

设定:

  • Windows 2000教授
  • .NET 2.0应用程序
  • 使用MySQL ODBC-Connector 3.51.26
  • 通过ODBCConnection连接到MySQL 5.0

我在遇到此异常时正在部署我的应用程序:

at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
at System.Data.Odbc.OdbcDataReader.GetData(Int32 i, SQL_C sqlctype, Int32 cb, Int32& cbActualOut)
at System.Data.Odbc.OdbcDataReader.internalGetString(Int32 i)
at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i, TypeMap typemap)
at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i)
at System.Data.Odbc.OdbcDataReader.GetValues(Object[] values)
at MyAppl.UninterestingStackTace.StartsHere()

是的,这只是堆栈跟踪...因为没有Exception-Message,也没有InnerException(我也记录了自上次遇到的那些),这就是我得到的。

代码如下所示:

// DtRdr is a passed in ODBCDataReader
if (DtRdr != null && !DtRdr.IsClosed)
{
    Object[] buffer = new Object[DtRdr.FieldCount];

    while (DtRdr.Read())
    {
        DtRdr.GetValues(buffer); // Here happens the exception

        // Modify buffer and use it
    }
}

它只发生在那台机器上,获取的数据/数据库很好(通过同一网络上的另一台机器验证它,我也在我的开发机器上本地测试),当然它在任何其他机器上都不可重复。

在Reflector中查看它时,我意识到从连接中读取数据似乎是一个问题。所有其他操作都运行正常,我可以直接访问数据,只有GetValues失败。

我写了一个快速而简单的测试应用程序,它会产生相同的错误,但在终止后也会输出以下语句:

Error in my_thread_global_end(): 1 threads didn't exit

我不确定这是否相关,对此感到抱歉。

我又迷失了......有没有人见过这样的事情?

编辑:这是我的测试应用程序:

using System;
using System.Data;
using System.Data.Odbc;

namespace ODBCTest
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            try {
                Console.WriteLine ("Creating connection...");
                using (OdbcConnection conn = new OdbcConnection ("ConnStringHere")) {
                    conn.Open ();
                    Console.WriteLine ("Creating command...");
                    using (OdbcCommand cmd = conn.CreateCommand ()) {
                        cmd.CommandText = "SimpleSelectHere;";

                        Console.WriteLine ("Creating reader...");
                        using (OdbcDataReader rdr = cmd.ExecuteReader ()) {
                            if (rdr != null && !rdr.IsClosed) {
                                while (rdr.Read ()) {
                                    object[] temp = new object[rdr.FieldCount];
                                    rdr.GetValues (temp);
                                }

                                Console.WriteLine ("Seems to work fine.");
                            } else {
                                Console.WriteLine ("Could not create reader!");
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine (ex.Message);
                Console.WriteLine (ex.StackTrace);
                Console.WriteLine ();
                if (ex.InnerException != null)
                {
                    Console.WriteLine (ex.InnerException.Message);
                    Console.WriteLine (ex.InnerException.StackTrace);
                } else {
                    Console.WriteLine("No InnerException.");
                }
            }

            Console.ReadKey ();
        }
    }
}

它的输出:

Creating connection...
Creating command...
Creating reader...

   at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
   at System.Data.Odbc.OdbcDataReader.GetData(Int32 i, SQL_C sqlctype, Int32 cb, Int32& cbActualOut)
   at System.Data.Odbc.OdbcDataReader.internalGetString(Int32 i)
   at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i, TypeMap typemap)
   at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i)
   at System.Data.Odbc.OdbcDataReader.GetValues(Object[] values)
   at ODBCTest.MainClass.Main(String[] args)

No InnerException.
<At this point I hit a key>
Error in my_thread_global_end(): 1 threads didn't exit

2 个答案:

答案 0 :(得分:3)

我会被诅咒!这是bug in the MDAC 2.7,安装2.8(或修补程序)修复此问题。

线程错误消息是the used MySQL ODBC-Connector中的错误。

答案 1 :(得分:0)

我在使用Sybase DB时也在MDAC 2.6 SP2中发现了这个问题,在我的情况下安装版本2.8 SP1是有帮助的。