SQL Server Compact Edition サブスクリプションを削除する方法 (プログラム)

ここでは、SqlCeReplication クラスを使用して Microsoft SQL Server 2005 Compact Edition (SQL Server Compact Edition) データベース上のサブスクリプションを削除する方法について学習します。SqlServerCe 名前空間の使用については、SqlServerCe 名前空間のリファレンス ドキュメントを参照してください。

SQL Server Compact Edition サブスクリプションを削除するには

  1. SqlCeReplication オブジェクトを初期化します。

  2. SqlCeReplication オブジェクトの以下のプロパティを設定します。

    • SubscriberConnectionString
    • Subscriber
    • Publisher
    • Publication
    • PublisherDatabase
  3. DropSubscription メソッドを呼び出し、DropOption を渡します。DropOption では、データベースを保持することも、削除することもできます。DropDatabase の DropOption を指定した場合、データベースに複数のサブスクリプションが含まれているときは、データベースは削除されません。

使用例

この例では、MyDatabase.sdf という名前のデータベースでサブスクリプションを削除する方法を示します。サブスクリプションが削除された後に、データベースが削除されます。

        SqlCeReplication repl = null;
        try 
    {
            // Set the Replication object properties.
            repl = new SqlCeReplication();
            repl.SubscriberConnectionString = 
  @"Data Source='ssce.sdf'";
            repl.Publisher = @"servername";
            repl.PublisherDatabase = @"SQLMobile";
            repl.Publication = @"SQLMobile";

            // Drop the subscription and delete the database.
            repl.DropSubscription(DropOption.DropDatabase);
        }
        catch(SqlCeException ex)
   {
            // Use your own error handling routine to show error information.
            // ShowError.ShowErrors(ex);
        }
        finally 
        {
            // Dispose of the Replication object.
            repl.Dispose();
        }
      Dim repl As SqlCeReplication = Nothing
      Try
         ' Set the Replication object properties.
         repl = New SqlCeReplication()
         repl.SubscriberConnectionString = "Data Source='ssce.sdf'"
         repl.Publisher = "servername"
         repl.PublisherDatabase = "SQLMobile"
         repl.Publication = "SQLMobile"

         ' Drop the subscription and delete the database.
         repl.DropSubscription(DropOption.DropDatabase)
      
      Catch ex As SqlCeException
      ' Use your own error handling routine to show error information.
      ' ShowErrors(ex)
      
      Finally
         ' Dispose of the Replication object.
         repl.Dispose()
      End Try
   ISSCEMerge      *pISSCEMerge = NULL;
   BSTR            bstr = NULL;

   /* Create the Replication object. */
   CoCreateInstance(CLSID_Replication, NULL, CLSCTX_INPROC_SERVER,
      IID_ISSCEMerge, (LPVOID *) &pISSCEMerge);
   
   /* Set Subscriber properties. */
   bstr = SysAllocString(L"data source=\\Ssce.sdf");
   pISSCEMerge->put_SubscriberConnectionString(bstr);
   SysFreeString(bstr);

   bstr = SysAllocString(L"SamplePublisher");
   pISSCEMerge->put_Publisher(bstr);
   SysFreeString(bstr);

   bstr = SysAllocString(L"AdventureWorks_SQLCE");
   pISSCEMerge->put_PublisherDatabase(bstr);
   SysFreeString(bstr);

   bstr = SysAllocString(L"SQLCEReplDemo");
   pISSCEMerge->put_Publication(bstr);
   SysFreeString(bstr);

   /* Drop the subscription and delete the database. */
   pISSCEMerge->DropSubscription(DROP_DATABASE));

参照

概念

マージ レプリケーションの使用
サブスクリプションの削除

ヘルプおよび情報

SQL Server Compact Edition のサポートについて