12

What happens if a database reaches the limit of 4GB of the SQL Server Compact Edition? Is there a special exception for this?

Can I safely catch this event or exception and, let's say, create a new database?

Gustavo Mori
  • 8,319
  • 3
  • 38
  • 52
flash
  • 6,730
  • 7
  • 46
  • 70

1 Answers1

8

I have not experienced this myself, but it looks like a SqlCeException will be thrown and the NativeError property of the contained SqlCeError will have an error code of 25104 (SSCE_M_DATABASETOOBIG).

Here's a listing of SqlCeError Native Codes related to db engine errors -- the one about the db file being too big is about 2/3 of the way down. The listing is for SQL CE 3.5; you didn't specify what version you were using, but I'm guessing that it wouldn't change.

I don't see why you couldn't catch this exception and then create a new database in your catch section.

try {
  //do something
} catch (SqlCeException cexc){
  foeach (SqlCeError aError in cexc.Errors) {
    if (aError.NativeError == 25104) {  //this is the code for the TOO BIG error code
      //handle too big error -- maybe create a new database
    }
  }
}

I hope this helps!

David Hoerster
  • 28,421
  • 8
  • 67
  • 102