Seth
Seth

Reputation: 8373

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.

Upvotes: 6

Views: 4406

Answers (2)

Tom Hunter
Tom Hunter

Reputation: 5918

Alternatively using the 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>

Upvotes: 6

Seth
Seth

Reputation: 8373

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.

Upvotes: 8

Related Questions