Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)
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.
The following sample demonstrates how to create a new SQL Server Compact Edition database.
If File.Exists("Test.sdf") Then File.Delete("Test.sdf") End If Dim connStr As String = "Data Source = Test.sdf; Password = <password>" Dim engine As New SqlCeEngine(connStr) engine.CreateDatabase() engine.Dispose() Dim conn As SqlCeConnection = Nothing Try conn = New SqlCeConnection(connStr) conn.Open() Dim cmd As SqlCeCommand = conn.CreateCommand() cmd.CommandText = "CREATE TABLE myTable (col1 int, col2 ntext)" cmd.ExecuteNonQuery() Catch Finally conn.Close() End Try