Export (0) Print
Expand All

SqlCeEngine Class

Represents the properties, methods, and other objects of the SQL Server Compact 3.5 SP1 Engine object. This class cannot be inherited.

Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)

public sealed class SqlCeEngine : IDisposable
public final class SqlCeEngine implements IDisposable
public final class SqlCeEngine implements IDisposable

SQL Server Compact 3.5 SP1 is not optimized to serve as a database for Web sites. By default, connections from ASP.NET-connected applications are blocked in SQL Server Compact 3.5 SP1. SQL Server Compact 3.5 SP1 is optimized for use as an embedded database within applications. Using SQL Server Compact 3.5 SP1 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, including SQL Server 2005 Express Edition and later versions, are optimized to serve as a database for Web sites.

SQL Server Compact 3.5 SP1 can be used with ASP.NET in application scenarios where ASP.NET is used to create SQL Server Compact 3.5 SP1 databases for synchronization scenarios. Use the following code to change the default behavior of SQL Server Compact 3.5 SP1 to work within ASP.NET.

AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true)


System.Object
  System.Data.SqlServerCe.SqlCeEngine

The following sample demonstrates how to create a new SQL Server Compact 3.5 SP1 database.

if (File.Exists("Test.sdf"))
    File.Delete("Test.sdf");

string connStr = "Data Source = Test.sdf; Password = <password>";
 
SqlCeEngine engine = new SqlCeEngine(connStr);
engine.CreateDatabase();
engine.Dispose();

SqlCeConnection conn = null;

try {
    conn = new SqlCeConnection(connStr);
    conn.Open();

    SqlCeCommand cmd = conn.CreateCommand();
    cmd.CommandText = "CREATE TABLE myTable (col1 int, col2 ntext)";
    cmd.ExecuteNonQuery();
}
catch {}
finally {
    conn.Close();
}

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Development Platforms

Windows Vista, Windows Mobile 5.0, Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Mobile 2003 for Pocket PC, Windows CE 5.0
Version Information
.NET Framework and NET Compact Framework
Supported in 3.5
.NET Framework
Supported in 3.0
.NET Compact Framework and .Net Framework
Supported in 2.0

Show:
© 2014 Microsoft