System.Data.SQLite issue on compact Framework 3.5

允我心安 提交于 2019-12-10 18:25:43

问题


I am using sqlite in my compact framework application to log the events in system. I am also using System.Data.SQLite. The event has the time stamp to describe at what time it occurred. I am storing this Time stamp as Ticks in my table. Along with this column the table contains another 5 columns of integer/text type. Below is table schema

CREATE TABLE T1 (TimeStamp INTEGER, Col2 INTEGER, Col3 INTEGER, Col4 INTEGER,
                      Col5 INTEGER, Col6 TEXT, PRIMARY KEY(TimeStamp DESC));

I am querying for the data between two time stamp using ADO with below query

SELECT TimeStamp,Col1,Col2,Col3,Col4,Col5 FROM T1 WHERE TimeStamp 
BETWEEN @startDate AND @endDate LIMIT 2000;

I am converting the Time stamp given by the user to Ticks and sending them as parameter values for '@startDate' and '@endDate'.

After I executed above query then I start iterating over SqLiteDataReader using while loop there I found that this while loop never comes out and continue to execute endlessly. Ideally it should end after reading 2000 records. Below is code snippet.

SQLiteDataReader dr = cmd.ExecuteReader();

    while(dr.Read())
    {
        :
        : Fill the data from column into Event class object
        :
    }

Please let me know if anybody has faced same issue.

EDIT :- After investigation I found that this problem comes up on fully loaded system. I simulate the environment of fully loaded system and tried on it.


回答1:


You could always solve it in another way, eliminating the LIMIT 2000 from the SQL and slightly changing your read logic like this:

var dr = cmd.ExecuteReader();
var rows = 0;

while(dr.Read())
{
    if(++rows > 2000) break;

    //
    // Fill the data from column into Event class object
    //
}


来源:https://stackoverflow.com/questions/14119713/system-data-sqlite-issue-on-compact-framework-3-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!