Search code examples
c#-4.0odbcdbase

Having problems with sustained usage of odbc with dBase files in C#


Here is my code:

    private const string CONNECTION_STRING
    = "Driver={Microsoft dBase Driver (*.dbf)};"
    + "collatingsequence=ASCII;"
    + "defaultdir={0};"
    + "driverid=277;"
    + "maxbuffersize={1};"
    + "pagetimeout={2}";

    string connString = string.Format(CONNECTION_STRING, filePath, MAX_BUFFER_SIZE, PAGE_TIMEOUT);

    using (var _conn = new System.Data.Odbc.OdbcConnection(connString))
    {
      _conn.Open();
      using (var _comm = _conn.CreateCommand())
      {
        _comm.CommandText = QUERY_STRING;
        _comm.CommandType = CommandType.Text;
        using (var rdr = _comm.ExecuteReader())
        {
          while (rdr.Read())
          {
            /*Do something*/
          }
        }
      }
    }

The error message I am getting is SQL Execution Error. Executed SQL statement: SELECT * FROM MyTable Error Source odbcjt32.dll Error Message Error [HY001][Microsoft][ODBC dBase Driver] System resource exceeded.

Several Gigs of RAM and HD open, before and after the query. And this always works on the first pass, but fails on all consecutive passes.

Running in Win 7 64, and .NET 4.0.

When I get the error, I end up rebooting to clear it. Though I haven't tried just doing a GC flush yet.


Solution

  • Since I could reliably read the file once, I ended up reading the whole file into memory, then just used that. Every event that would force the memory space to be dumped would also fix the problem with the connection not releasing the file lock, so reloading the file into memory wasn't a problem either.

    If I end up finding a better solution, I will post it too. However, I think this is a dead thread since the project has been closed, delivered, and paid.