简体   繁体   中英

System.Data.SQLite issue on compact Framework 3.5

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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