Problems connecting to old DBF with OleDB and .NET (C#)
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 :)

