Partilhar via


SqlCeEngine Constructor (String)

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 with the specified local connection string.

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

Parameters

  • localConnectionString
    src connection string

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

Platforms: .NET Compact Framework

.NET Framework Security:

See Also

SqlCeEngine Class | SqlCeEngine Members | System.Data.SqlServerCe Namespace | SqlCeEngine Constructor Overload List

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

Send comments on this topic.

© Microsoft Corporation. All rights reserved.