Problems connecting to old DBF with OleDB and .NET (C#)

I'm connecting to an old DBF file (dBase 5.0) and after sevral commands are executed (about 570-590 times)

it shows me thw following error

ERROR [HY001] [Microsoft][ODBC dBase Driver] System resource exceeded.

and reading the DB failes after that for good.

private void CollectDBData()
{
try
{
// Defining OdbcConnection to connect to DB.
OdbcConnection conn = new OdbcConnection();
OdbcDataReader reader = null;



while ((m_areThreadActive) &&
(Thread.CurrentThread.ThreadState ==
System.Threading.ThreadState.Running))
{
try
{

// Setting connection string.
conn.ConnectionString = @"Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=c:\";

// Opening connection to DB.
conn.Open();

// Creating sql select command string.
string commandStr = "SELECT * FROM TABLE1";



// Creating sql select command.
OdbcCommand comm = new OdbcCommand(commandStr, conn);



// Executing command!

reader = comm.ExecuteReader();



while ((reader!=null) && (reader.Read()))
{
string data = GetColumnValStr(reader,DBColumnsEnum.DATA1));

// This data is inserted to queue for another thread to handle.

}

reader.Close();
reader = null;
comm.Dispose();
conn.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
// Closing connection to DB.
if (reader != null)
{
reader.Close();
}
if (conn != null)
{
conn.Close();
}
}

Thread.Sleep(1000);
}
}
catch (Exception exc)
{
Console.WriteLine(exc.Message);
}

}

private string GetColumnValStr(OdbcDataReader reader, DBColumnsEnum column)
{
try
{
string col = column.ToString().ToUpper();
return Encoding.GetEncoding(1255).GetString(
Encoding.GetEncoding(862).GetBytes(reader[col].ToString()));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return string.Empty;
}

the thread sleeps for 1 second (in the real code it is changable by app.config)

but for frequent updated sometime it will be as low as 1 sec...



i've tried everything and it didn't work

in the end i see the message...

(i'm closing the connection and clearing the DataReader and Command as you can see)



i get another message

ERROR [HY000] [Microsoft][ODBC dBase Driver] Unexpected error from external database driver (15877).

sometimes after i start my program sometimes in the middle



this something i've searched the web and came out empty

except shuting down the application and opening it again

not a good thing for me

and replcaing the DB ain't possible cause it's not my system and i can't touch\don't have the code

(this application works over another application's DB without changing the data in it, only readiing it)



anyway, every help will be much appreciated to solve this mind crazy problems



Thanks :)
[4588 byte] By [Nesher] at [2007-11-20 10:04:20]
# 1 Re: Problems connecting to old DBF with OleDB and .NET (C#)
I've tried to play with connection string and other stuff
i also tried connecting through Access file and got same errors...

this thing is driving me nuts

btw i'm using the latest MDAC (2.8 SP1) and the computer is running win 2000

in the mean while running the same application on win 2003 over 3-4 times the time i run on the destination computer
Nesher at 2007-11-10 3:30:01 >
# 2 Re: Problems connecting to old DBF with OleDB and .NET (C#)
anyone?
this is very important... thanks!!
Nesher at 2007-11-10 3:31:01 >
# 3 Re: Problems connecting to old DBF with OleDB and .NET (C#)
If you want a query a database once a second you might as well leave the connection open and just repeatedly run the query, than tear it down and make a new one every second.. There could be any old crap hanging aroudn that keeps the conenction open.. 500 connections later whatever resource is available is "exceeded"
cjard at 2007-11-10 3:32:04 >