How to specify the location of the SDF file using SQLSERVER.MOBILE.OLEDB.3.0

Connection string

This Microsoft.SQLSERVER.MOBILE.OLEDB.3.0 connection string can be used for connections to SQL Server Compact.

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;