Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the maximum database size when using Entity Framework?

I am using Entity Framework and SQL CE 4.0 with my WPF application. How do I set the maximum database size in accordance with this article, http://blogs.msdn.com/b/sqlservercompact/archive/2007/06/13/the-story-of-max-database-size-connection-string-parameter.aspx which states:

we don't always grow to 4 GB, it is not wise to allocate shared memory to accommodate all page entries/references to support 4 GB.

Currently, I get the following error when trying to add new data:

The database file is larger than the configured maximum database size.

However, the DB is only reaching close to 256MB, which is in line with the article in the link above.

like image 704
Seth Avatar asked Nov 02 '11 02:11

Seth


1 Answers

This seems to work:

SqlCeConnectionFactory sqlCeConnection = 
    new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", 
    "", "Max Database Size=4000;Persist Security Info=False;");
DbDatabase.DefaultConnectionFactory = sqlCeConnection;
DbDatabase.SetInitializer(new SampleData());

Where the third parameter is the connection string and you change the parameter Max Database Size otherwise it defaults to 256MB.

like image 185
Seth Avatar answered Nov 15 '22 07:11

Seth