SqlCeEngine Class
Represents the properties, methods, and other objects of the Engine object. This class cannot be inherited.
Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)
Syntax
'Declaration
Public NotInheritable Class SqlCeEngine _
Implements IDisposable
'Usage
Dim instance As SqlCeEngine
public sealed class SqlCeEngine : IDisposable
public ref class SqlCeEngine sealed : IDisposable
[<SealedAttribute>]
type SqlCeEngine =
class
interface IDisposable
end
public final class SqlCeEngine implements IDisposable
Remarks
is not optimized to serve as a database for Web sites. By default, connections from -connected applications are blocked in . is optimized for use as an embedded database within applications. Using 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 , including and later versions, are optimized to serve as a database for Web sites.
can be used with in application scenarios where is used to create databases for synchronization scenarios. Use the following code to change the default behavior of to work within .
AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true)
Examples
The following sample demonstrates how to create a new 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
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();
}
Inheritance Hierarchy
System. . :: . .Object
System.Data.SqlServerCe..::..SqlCeEngine
Thread Safety
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.