Coming soon - Get a detailed view of why an account is flagged as spam!
view details
4
[c#][odbc] ODBCDataReader hangs randomly?
Author Summary
stereoa is in odbc
Post Body

So, I have a huge query that I need to run on an Access DB. I am attempting to use a for loop to break it down because I can't run the query all at once (it has an IN with 50k values). The reader is causing all kinds of problems hanging and such. Most times when I break up the for loop into 50-10000 values the reader will read 400 (exactly 400) values and then hang for about 3 minutes then do another hundred or so, hang, ad infinium. If I do over 10k values per query it gets to 2696 and then hangs, does another 1k or so after hanging, on and on. I have never really worked with odbc, sql or any type of database for that matter, so it must be something stupid, or is this expected? Maybe there's a better way to do something like this? Here's my code that is looped:

//connect to mdb
OdbcConnection mdbConn = new OdbcConnection();
mdbConn.ConnectionString = @"Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\PINAL_IMAGES.mdb;";
mdbConn.Open();

OdbcCommand mdbCmd = mdbConn.CreateCommand();
mdbCmd.CommandText = @"SELECT RAW_NAME,B FROM 026_006_886 WHERE (B='CM1' OR B='CM2') AND MERGEDNAME IN"   imageChunk;
OdbcDataReader mdbReader = mdbCmd.ExecuteReader();

while (mdbReader.Read())
{
  sw.WriteLine(@"for /R %%j in ("   mdbReader[0]   @") do move %%~nj.tif .\"   mdbReader[1]   @"\done");
  linesRead  ;
  Console.WriteLine(linesRead);
}
mdbConn.Close();

Here's how I populate the imageChunk variable for the IN by reading 5000 lines with a value line from a text file using a StreamReader:

            string imageChunk = "(";
            for (int j = 0; j < 5000; j  )
            {
                string image;
                if ((image = sr.ReadLine()) != null)
                {
                    imageChunk  = @"'"   sr.ReadLine()   @"',";
                }
                else
                {
                    break;
                }
            }
            imageChunk = imageChunk.Substring(0, imageChunk.Length - 1);
            imageChunk  = ")";

Author
Account Strength
100%
Account Age
15 years
Verified Email
Yes
Verified Flair
No
Total Karma
20,722
Link Karma
1,874
Comment Karma
18,378
Profile updated: 5 days ago
Posts updated: 9 months ago

Subreddit

Post Details

Location
We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
13 years ago