简体   繁体   English

ODBC数据检索问题

[英]ODBC Data Retrieval Issue

I wrote an app to pull data from a ProvideX database, and after a while I noticed that some fields were returning null, even though I knew they had data in them. 我写了一个应用程序从ProvideX数据库中提取数据,过了一会儿,我注意到有些字段返回空值,即使我知道它们中包含数据。 I confirmed this in Excel/MSQuery. 我在Excel / MSQuery中确认了这一点。

I couldn't figure out what I might be doing wrong, so I pulled out the code that directly deals with the query, and ran it in its own project. 我不知道自己可能在做错什么,因此我取出直接处理查询的代码,并在自己的项目中运行它。 It pulled the data properly, even though it was the same code in the actual app. 即使它与实际应用程序中的代码相同,它也可以正确提取数据。

In my app, I use both ODBCDataAdapter and ODBCDataReader. 在我的应用程序中,我同时使用了ODBCDataAdapter和ODBCDataReader。 I use the adapter.Fill() first, and if it fails, the app uses the reader. 我首先使用adapter.Fill(),如果失败,则应用使用阅读器。 Both of these have the same behavior I outlined above: inside the app they fail to properly retrieve some fields, outside the app by themselves they work as expected. 两者的行为与我上面概述的相同:在应用程序内部,它们无法正确检索某些字段;在应用程序外部,它们本身无法按预期工作。

Can anyone point me to some possibilities that might cause the ODBC stuff to have such issues? 谁能指出一些可能导致ODBC出现此类问题的可能性?

I guess I should clarify that I am not asking what is wrong with my code, but rather, general troubleshooting hints as to what might cause this issue for the ODBC framework. 我想我应该澄清的是,我不是在问我的代码有什么问题,而是关于可能导致ODBC框架出现此问题的一般故障排除提示。

EDIT : 编辑:

Ok, let me add some more info here... 好的,让我在这里添加更多信息...

The main problem seems to be in the DataReader code, specifically the Read() method. 主要问题似乎在DataReader代码中,尤其是Read()方法。 For some reason, inside my app, the Read() method takes at least a second to execute and many times it takes a bit over 3 seconds. 出于某种原因,在我的应用程序内部,Read()方法至少需要花费一秒钟的时间来执行,而很多时候却要花3秒钟以上的时间。 By comparison, outside my app, the entire query code, including populating the DataTable, runs in under 30 seconds. 相比之下,在我的应用程序外部,整个查询代码(包括填充DataTable)的运行时间不到30秒。 This is for about 3 thousand rows with 370 columns. 这是关于370列的约3000行。

The while loop... while循环...

// Column ordinals cached
// I pared down the code inside the while loop, populating a list of
//  arrays (rows) to hold the raw data. This was the quickest way I 
// could think of to do this. TryGetValue is an extension method 
// that handles null exceptions.
while(reader.Read())
{
    var arr = new object[reader.FieldCount];
    for (i = 0; i < arr.Length; i++)
    {
        arr[i] = reader.TryGetValue(ordinals[i]);
    }
    rows.Add(arr);
}

Why the difference?? 为什么会有所不同?

Ok, after much testing, I narrowed the problem to a single Date field that was somehow throwing the whole query off. 好的,经过大量测试,我将问题缩小为单个Date字段,以某种方式使整个查询失败。 I dealt with this by adding a rule to skip that column when querying the ProvideX database. 我通过在查询ProvideX数据库时添加一条跳过该列的规则来解决此问题。

I'm afraid I can't yet say why that field does not get along with ODBC, still waiting to hear from the vendor (not even sure if I ever will). 恐怕我还不能说为什么该字段与ODBC不一致,而仍在等待供应商的来信(甚至不确定我是否愿意)。 I do know that this ProvideX database is a flat file database, so I guess they had that particular field set up badly. 我确实知道这个ProvideX数据库是一个平面文件数据库,所以我想他们在该特定字段上的设置很差。

I hope this helps others who may find themselves dealing with such an obscure database... 我希望这对其他可能发现自己处理如此晦涩的数据库的人有所帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM