Microsoft provides two different providers to connect to the SQL Server Compact database:
• Microsoft .NET Compact Framework Data Provider for SQL Server Mobile (SqlCeConnection)
• Microsoft .NET Compact Framework Data Provider for OLEDB (OleDbConnection)
You can connect to your SQL Server CE database using the following code:
_connection = new SqlCeConnection(
"Data source='Salesforce.sdf';Password=admin123;"); _connection.Open();
It is recommended to use SqlCeConnection whenever possible, as these are native SQL Server CE providers. The OledbConnection provider is a generic provider that will perform data type conversions and other operations under the hood and so its performance will be slower than that of SqlCeConnection.
connection.Close(); connection.Dispose(); connection = null;
Was this article helpful?