SQL Server Compact
Standard
Provider=Microsoft.SQLSERVER.MOBILE.OLEDB.3.0;Data Source=myPath\myData.sdf;
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.
Provider=Microsoft.SQLSERVER.MOBILE.OLEDB.3.0;Data Source=" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\MyData.sdf;
Specifying the maximum database size
The maximum size of the database is by default 128 MB. Override this by using the following connection string.
Provider=Microsoft.SQLSERVER.MOBILE.OLEDB.3.0;Data Source=myPath\myData.sdf;SSCE:Max Database Size=256;
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.
Provider=Microsoft.SQLSERVER.MOBILE.OLEDB.3.0;Data Source=myPath\myData.sdf;SSCE:Max Buffer Size=1024;
Encryption enabled
Use this connection string to enable encryption on the database.
Provider=Microsoft.SQLSERVER.MOBILE.OLEDB.3.0;Data Source=myPath\myData.sdf;SSCE:Encrypt Database=True;
Specifying the maximum temp file size
The maximum size of the temporary database file is by default 128 MB. Override this by using the following connection string.
Provider=Microsoft.SQLSERVER.MOBILE.OLEDB.3.0;Data Source=myPath\myData.sdf;SSCE:Temp File Max Size=256;
Specifying location of temp file
Set the directory for the temp file location using this connection string.
Provider=Microsoft.SQLSERVER.MOBILE.OLEDB.3.0;Data Source=myPath\myData.sdf;SSCE:Temp File Directory="\myTempDir\";
Supplying the database password
Use this connection string to provide the database password when opening the connection.
Provider=Microsoft.SQLSERVER.MOBILE.OLEDB.3.0;Data Source=myPath\myData.sdf;SSCE:Database Password='myPassword';