Tuesday, July 10, 2012

Connection strings for SQL Server Compact Edition

Standard

Data Source=MyData.sdf;Persist Security Info=False;

How to specify the location of the SDF file

Often times the .SDF database is not running in the current directory so it becomes necessary to programatically set the path to the SDF file. This is an example (.net C#) on how to do this when the SDF file is located in the same directory as the executing application.
Data Source=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\MyData.sdf;Persist Security Info=False;

Standard

Data Source=MyData.sdf;Persist Security Info=False;

Specifying the maximum database size

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;

Specifying the maximum buffer size

The largest amount of memory that can be in use before the server starts flushing changes to disk is by default 640 kB. Override this by using the following connection string.
Data Source=MyData.sdf;Max Buffer Size=1024;Persist Security Info=False;

Encryption enabled

Use this connection string to enable encryption on the database.
Data Source=MyData.sdf;Encrypt Database=True;Password=myPassword;File Mode=shared read;Persist Security Info=False;

Share : Connection strings for SQL Server Compact Edition

Related Posts

Connection strings for SQL Server Compact Edition
4/ 5
Oleh