Question

I'm using Sql Compact3.5 as my DB with C# .NET what is the maximum size of sdf that I can give??? Is there any way to programatically increase the maximum size of the sdf file??? if so how???

Was it helpful?

Solution

The maximum size of the database is by default 128 MB. Override this by using the following connection string.

Data Source=MyData.sdf;Max Database Size=256;Persist Security Info=False;

(from: http://www.connectionstrings.com/sql-server-2005-ce) and (from: http://msdn.microsoft.com/...)

The absolute maximum size of the database is 4gb.

OTHER TIPS

Just for the benefit of people searching...

If your SQL CE database is published and in use, you can still increase the size by changing the Max Database Size in the connection string (as above). You are not stuck with the value you initially choose.

http://blogs.msdn.com/b/sqlservercompact/archive/2007/06/13/the-story-of-max-database-size-connection-string-parameter.aspx

As Benny Jobigan said, you can specify a maximum size via the connection string.

However, the size specified must be between 16 and 4091. If you specify a size outside if this, the following exception is thrown (from the C# SQL Server Compact 3.5 library):

System.ArgumentException: The value of ssce:max database size token is outside of range of allowed values (16,4091).

Actually, Max Database Size should be pointed as from 16 to 4091 in Microsoft SQL CE 4.0. Default value is 257 (Mb). I tried to use 4096 (exactly 4Gb) and error occured. 4091 is valid value, and now my connection string looks like:

Data Source=file.sdf; Max Database Size=4091

If you use Microsoft SQL Compact Edition along with Entity Framework (I do), the connection string for EF looks like this:

string template = "metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlServerCe.4.0;"
                + "provider connection string=\";Data Source={0}; Max Database Size=4091 \";";
string s1 = string.Format(template, SdfFilePath);

where Model is the name of your edmx file.

Right Click on Database name in Server Explorer And select "Modify Connection". Click on Advanced Button .you can Change Database Default Size

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top