Share via


SqlCeEngine クラス

SQL Server Compact 3.5 エンジン オブジェクトのプロパティ、メソッド、および他のオブジェクトを表します。このクラスは継承できません。

名前空間:  System.Data.SqlServerCe
アセンブリ:  System.Data.SqlServerCe (System.Data.SqlServerCe.dll)

構文

'宣言
Public NotInheritable Class SqlCeEngine _
    Implements IDisposable
'使用
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

説明

SQL Server Compact 3.5 は Web サイトのデータベースとして機能するように最適化されていません。既定では、ASP.NET 接続アプリケーションからの接続は、SQL Server Compact 3.5 内でブロックされます。SQL Server Compact 3.5 は、アプリケーション内で組み込み型データベースとして使用するために最適化されています。SQL Server Compact 3.5 を Web サイト用のデータベースとして使用するには、複数ユーザーやデータの同時更新をサポートする必要があります。これにより、パフォーマンスに問題が発生する可能性があります。このため、これらの利用方法はサポートされていません。SQL Server 2005 Express Edition 以降のバージョンなど、他のエディションの SQL Server は、Web サイトに使用するデータベースとして最適化されています。

同期する場合のために ASP.NET を使用して SQL Server Compact 3.5 データベースを作成するアプリケーションでは、SQL Server Compact 3.5 を ASP.NET で使用できます。ASP.NET で動作するように SQL Server Compact 3.5 の既定の動作を変更するには、次のコードを使用してください。

AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true)

使用例

新しい SQL Server Compact 3.5 データベースを作成する方法を次のサンプルに示します。

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();
}

継承階層

System. . :: . .Object
  System.Data.SqlServerCe..::..SqlCeEngine

スレッド セーフ

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.

関連項目

参照

SqlCeEngine メンバー

System.Data.SqlServerCe 名前空間