How to set maximum database size when using Entity Framework?

I am using Entity Framework and SQL CE 4.0 with my WPF application. How to set the maximum database size according to 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 do not always grow up to 4 GB, it is impractical to allocate shared memory to accommodate all the records / links to pages to support 4 GB.

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

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

However, the database reaches only 256 MB, which corresponds to the article in the link above.

+6
source share
2 answers

It works:

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

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

+8
source

Alternatively, using app.config :

 <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework"> <parameters> <parameter value="System.Data.SqlServerCe.4.0"/> <parameter value=""/> <parameter value="Max Database Size=4000"/> </parameters> </defaultConnectionFactory> </entityFramework> 
+6
source

Source: https://habr.com/ru/post/900580/


All Articles