SqlServerCE version 3.5 SP2 - Database file is larger than configured maximum
Here is some sample code of how I am creating/connecting/working with my database
string connection = @"Data Source='C:\test.sdf';Max Database Size=4000;"
+ "Max Buffer Size=4096;";
File.Delete(@"C:\test.sdf");
using (var engine = new SqlCeEngine(connection))
{
engine.CreateDatabase();
engine.Compact("Data Source=; Case Sensitive=True; Max Database Size=4000;");
}
using (var dbConn = new SqlCeConnection(connection))
{
// Create tables, indexes, etc, and insert loads of data here
// Somewhere in th开发者_如何学Pythone loading of data I get
// the "Database file is larger..." exception
}
Here is my question. The database file size at the point of the exception is a mere 368 MB (386,879,488 bytes to be exact according to the file properties). Do I need to add the max database size string into the Compact statement?
Any other ideas on what could be wrong.
The default value for Max Database Size is 256 MB, so yes, you would need to add this to the connection string, if the file size grows over this.
As had ErikEJ said, this is how the connection string have to be:
"Data Source=MyData.sdf;Max Database Size=256;Persist Security Info=False;"
where you can replace 256 with a needed size.
精彩评论