How to: Drop a SQL Server Compact Edition Subscription (Programmatically)
In this topic, you will learn how to drop a subscription on a Microsoft SQL Server 2005 Compact Edition (SQL Server Compact Edition) database by using the SqlCeReplication class. For more information about using the SqlServerCe namespace, see the SqlServerCe namespace reference documentation.
To drop a SQL Server Compact Edition subscription
Initialize a SqlCeReplication object.
Set the following properties of the SqlCeReplication object:
- SubscriberConnectionString
- Subscriber
- Publisher
- Publication
- PublisherDatabase
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));
See Also
Other Resources
Using Merge Replication
Dropping a Subscription