Dulini Atapattu
Dulini Atapattu

Reputation: 2735

How to detect the Ms-Access database exceeds the max size using c sharp

I have an Ms-Access database (2003) and I have noticed that it gives OledbException: Invalid Argument when the database size exceeds 2GB (Which is the maximum size of the database).

Is there anyway of detecting that this exception was thrown exactly due the to the reason that database has exceeded its maximum size.(I need it to backup the database then)...

Thanks in advance

Upvotes: 0

Views: 1135

Answers (1)

O. Jones
O. Jones

Reputation: 108736

How about this:

constant long TWO_G = (2*1024*1024*1024); 
constant long MARGIN = (8 * 1024 * 1024); 
string pathToMonsterMdb = "monster.mdb";
FileInfo mdb = new FileInfo(pathToMonsterMdb);
long len = mdb.Length;
if (len > (TWO_G - MARGIN) {
   /* File's getting close to max size.  Deal with it. */
}

Of course, the real question is actually what to do about the problem. With a data base this size you probably want to move to a more robust table server.

If you set MARGIN big enough you can run this less often than after every single insert.

Upvotes: 1

Related Questions