SqlCeConnection Class
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)
A SqlCeConnection object represents a unique connection to a data source. When you create an instance of SqlCeConnection, all properties are set to their initial values. For a list of these values, see the SqlCeConnection constructor.
If the SqlCeConnection goes out of scope, it is not closed. You must explicitly close the connection by calling Close or Dispose.
Microsoft SQL Server 2005 Compact Edition supports multiple simultaneous connections as well as multiple commands sharing the same connection. This means that it is possible to have multiple instances of SqlCeDataReader open on the same connection. This behavior differs from that of System.Data.SqlClient.
If a fatal SqlCeException is generated by the method executing a SqlCeCommand, the SqlCeConnection may be closed. You can reopen the connection and continue.
SQL Server Compact Edition is not currently optimized to serve as a database for Web sites. By default, connections from ASP.NET-connected applications are blocked in SQL Server Compact Edition. SQL Server Compact Edition is optimized for use as an embedded database within applications. Using SQL Server Compact Edition as a database for Web sites requires support for multiple users and concurrent data changes. This can cause performance problems. Therefore, these scenarios are not supported. Other editions of SQL Server 2005, including SQL Server 2005 Express Edition, are optimized to serve as a database for Web sites.
SQL Server Compact Edition can be used with ASP.NET in application scenarios where ASP.NET is used to create SQL Server Compact Edition databases for synchronization scenarios. Use the following code to change the default behavior of Compact Edition to work within ASP.NET.
AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true)
The following example creates a SqlCeCommand and a SqlCeConnection. The SqlCeConnection is opened and set as the Connection for the SqlCeCommand. The example then calls ExecuteNonQuery and closes the connection.
Dim conn As SqlCeConnection = Nothing Try conn = New SqlCeConnection("Data Source = MyDatabase.sdf; Password ='<pwd>'") conn.Open() Dim cmd As SqlCeCommand = conn.CreateCommand() cmd.CommandText = "INSERT INTO Customers ([Customer ID], [Company Name]) Values('NWIND', 'Northwind Traders')" cmd.ExecuteNonQuery() Finally conn.Close() End Try
System.MarshalByRefObject
System.ComponentModel.Component
System.Data.Common.DbConnection
System.Data.SqlServerCe.SqlCeConnection