我似乎有幸碰到funniest problems while deploying my software。ODBCDataReader的GetValues期間發生空異常
設置:
- Windows 2000中教授
- .NET 2.0應用
- 連接到MySQL 5.0通過ODBCConnection使用MySQL的ODBC連接器3.51.26
我部署我的應用程序,而我遇到這個異常:
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
}
}
這只是那臺機器上發生的情況,所取得的數據/數據庫是很好的(通過另一臺機器上驗證它在同一網絡上,我也測試了它在本地對我的dev - 機器),當然它不能在任何其他機器上重現。
在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