This documentation is archived and is not being maintained.

SqlCeEngine Constructor

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

Initializes a new instance of the SqlCeEngine class.

Overload List

Initializes a new instance of the SqlCeEngine class.

Supported only by the .NET Compact Framework.

[Visual Basic] Public Sub New()
[C#] public SqlCeEngine();
[C++] public: SqlCeEngine();
[JScript] public function SqlCeEngine();

Initializes a new instance of the SqlCeEngine class with the specified local connection string.

Supported only by the .NET Compact Framework.

[Visual Basic] Public Sub New(String)
[C#] public SqlCeEngine(string);
[C++] public: SqlCeEngine(String*);
[JScript] public function SqlCeEngine(String);

Example

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

[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of the SqlCeEngine constructor. For other examples that might be available, see the individual overload topics.
[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.

See Also

SqlCeEngine Class | SqlCeEngine Members | System.Data.SqlServerCe Namespace

Show: