本主题将介绍如何通过使用 SqlCeReplication 类来删除对 Microsoft SQL Server 2005 Compact Edition (SQL Server Compact Edition) 数据库的订阅。有关使用 SqlServerCe 命名空间的详细信息,请参阅 SqlServerCe 命名空间参考文档。
删除 SQL Server Compact Edition 订阅
- 初始化 SqlCeReplication 对象。 
- 设置 SqlCeReplication 对象的下列属性: - SubscriberConnectionString
- Subscriber
- Publisher
- Publication
- PublisherDatabase
 
- 调用 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));