SqlCeEngine.CreateDatabase Method

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

Creates a new database.

  [Visual Basic]
  Public Sub CreateDatabase()

  [C#]
  public void CreateDatabase();
[C++]
public: void CreateDatabase();
[JScript]
public function CreateDatabase();

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

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

Send comments on this topic.

© Microsoft Corporation. All rights reserved.