ODBCDataReader 的 GetValues 期间出现空异常

发布于 2024-10-03 15:45:09 字数 4209 浏览 3 评论 0原文

我似乎很幸运在部署软件时遇到了 最有趣的问题

设置:

  • Windows 2000 Prof.
  • .NET 2.0 应用程序
  • 使用 MySQL ODBC 连接器 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()

是的,这只是堆栈跟踪...因为有没有异常消息,也没有 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

I seem to have the luck to run into the funniest problems while deploying my software.

Setup:

  • Windows 2000 Prof.
  • .NET 2.0 Application
  • Connection to MySQL 5.0 via ODBCConnection using the MySQL ODBC-Connector 3.51.26

I was deploying my application while I was running into this exception:

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()

Yes, that's only the stacktrace...because there is no Exception-Message, there's also no InnerException (I also log those since my last encounter), this is all I got.

The code looks like this:

// 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
    }
}

It's only happening on that machine, the fetched data/database is good (verified it via another machine on the same network and I also tested it locally on my dev-machine) and of course it's not reproducible on any other machine.

While looking at it in Reflector, I realize that it seems to be a problem with reading the data from the connection. All other operations are working fine, I can access the data directly, only GetValues fails.

I wrote a fast and simple test application which yields the same error, but also outputs the following statement after terminating:

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

I'm not sure if this is related or not, so sorry for the confusion.

I'm lost once again...has anyone seen something like this before?

Edit: Here's my test application:

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 ();
        }
    }
}

And it's output:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半夏半凉 2024-10-10 15:45:09

我会被诅咒的!这是MDAC 2.7 中的错误,安装 2.8 (或修补程序)修复了这个问题。

线程错误消息是 使用的 MySQL ODBC 连接器

I'll be damned! This is a bug in the MDAC 2.7, installing 2.8 (or the hotfix) fixes this.

And the thread-error message is a bug in the used MySQL ODBC-Connector.

稍尽春風 2024-10-10 15:45:09

我在使用 Sybase DB 时也在 MDAC 2.6 SP2 中观察到此问题,安装版本 2.8 SP1 对我的情况有所帮助。

I also observed this problem in MDAC 2.6 SP2 while working with Sybase DB, installing version 2.8 SP1 helped in my case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文