• .NET Compact Framework Data Provider for SQL Server Mobile

    • Standard

      Data Source=MyData.sdf;Persist Security Info=False;
      SQL Server Compact
    • 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;
      SQL Server Compact
    • 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;
      SQL Server Compact
    • 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;
      SQL Server Compact
    • 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;

      The Encrypt Database="True" pair is really not necessary as the presence of the Password-parameter itself turns on encryption for the connection.

      SQL Server Compact
    • Exclusive access

      Use this one to disallow other processes from opening or modifying the database while you have it open.

      Data Source=MyData.sdf;File Mode=Exclusive;Persist Security Info=False;
      SQL Server Compact
    • Read only access

      Use this one to open a read-only copy of the database.

      Data Source=MyData.sdf;File Mode=Read Only;Persist Security Info=False;
      SQL Server Compact
    • Exclusive but shared for reading

      Use this one to allow other processes to read, but not modify, the database while you have it open.

      Data Source=MyData.sdf;File Mode=Shared Read;Persist Security Info=False;
      SQL Server Compact
    • 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.

      Data Source=MyData.sdf;Temp File Max Size=256;Persist Security Info=False;
      SQL Server Compact
    • Case sensitive database

      Upon database creation the default is case insensitive, use this one for a case sensitive database.

      Data Source=MyData.sdf;Case Sensitive=True;Persist Security Info=False;

      This allows you to have multiple values, wich only deffer in lower / upper case, in a unique column.

      This setting is a database creation time option and is ignored when connecting to an existing database.

      SQL Server Compact

    Problems connecting?   Get answer in the SQL Server Compact Q & A forum →

  • Microsoft.SQLSERVER.CE.OLEDB.3.5

  • Microsoft.SQLSERVER.MOBILE.OLEDB.3.0

    • Standard

      Provider=Microsoft.SQLSERVER.MOBILE.OLEDB.3.0;Data Source=myPath\myData.sdf;
      SQL Server Compact
    • 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;
      SQL Server Compact
    • 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;
      SQL Server Compact
    • 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;
      SQL Server Compact
    • 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;
      SQL Server Compact
    • 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;
      SQL Server Compact
    • 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\";
      SQL Server Compact
    • 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';
      SQL Server Compact
  • .NET Framework Data Provider for OLE DB

    • Use an OLE DB provider from .NET

      Provider=any oledb provider's name;OledbKey1=someValue;OledbKey2=someValue;

      See the respective OLEDB provider's connection strings options. The .net OleDbConnection will just pass on the connection string to the specified OLEDB provider. Read more here.

Articlesread all

Didn't find your connection string?

Start over from the connection string reference index - or try a search!

In the Q&A forums you can ask your own question and let somebody help you.

The knowledge articles contains solutions and guides.