In this topic, you will learn how to drop a subscription on a Microsoft SQL Server Compact 3.5 database by using the SqlCeReplication class. For more information about using the SqlServerCe namespace, see the SqlServerCe namespace reference documentation.

Procedures for SQL Server Compact 3.5

To drop a subscription

  1. Initialize a SqlCeReplication object.

  2. Set the following properties of the SqlCeReplication object:

    • SubscriberConnectionString

    • Subscriber

    • Publisher

    • Publication

    • PublisherDatabase

  3. Call the DropSubscription method, passing in the DropOption. The DropOption lets you either keep the database or delete the database. If you specify a DropOption of DropDatabase and the database contains more than one subscription, the database will not be deleted.

Example

This example shows how to drop a subscription on a database named MyDatabase.sdf. After the subscription is dropped, the database is deleted.

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

Concepts

Using Merge Replication

Dropping a Subscription