Compartir a través de


SqlCeEngine Class

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Represents the properties, methods, and other objects of the SQL Server CE Engine. This class cannot be inherited.

For a list of all members of this type, see SqlCeEngine Members.

System.Object
   System.MarshalByRefObject
      System.Data.SqlServerCe.SqlCeEngine

  [Visual Basic]
  NotInheritable Public Class SqlCeEngine
   Inherits MarshalByRefObject
   Implements IDisposable

  [C#]
  public sealed class SqlCeEngine : MarshalByRefObject, IDisposable

  [C++]
  public __gc __sealed class SqlCeEngine : public MarshalByRefObject,
   IDisposable

  [JScript]
  public class SqlCeEngine extends MarshalByRefObject implements
   IDisposable

Thread Safety

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

Example

[Visual Basic, C#] The following sample demonstrates how to create a new SQL Server CE database.

  [Visual Basic] 
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

[C#] 
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();
}

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Data.SqlServerCe

Platforms: .NET Compact Framework

Assembly: System.Data.Sqlserverce (in System.Data.Sqlserverce.dll)

See Also

SqlCeEngine Members | System.Data.SqlServerCe Namespace

Syntax based on .NET Framework version 1.1.
Documentation version 1.1.1.

Send comments on this topic.

© Microsoft Corporation. All rights reserved.