Condividi tramite


SqlCeReplication.AddSubscription Method

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Creates a new anonymous subscription to an existing Microsoft SQL Server publication. After calling the AddSubscription method, the application must call the Synchronize method to synchronize the new subscription to the publication based on the latest snapshot.

  [Visual Basic]
  Public Sub AddSubscription( _
   ByVal 
  addOption
   As AddOption _
)
[C#]
public void AddSubscription(AddOption addOption
);
[C++]
public: void AddSubscription(AddOption addOption
);
[JScript]
public function AddSubscription(
   addOption : AddOption);

Parameters

  • addOption

Remarks

SQL Server CE replication only supports anonymous subscriptions.

The database administrator must configure SQL Server to support replication, create the SQL Server publication, and enable the publication for anonymous subscriptions before any SQL Server CE application can subscribe to the publication. The administrator does this on the SQL Server system using either the administrative or programmatic interfaces of SQL Server replication

The AddOption value specifies the source of the newly created SQL Server CE subscription database and can be one of these constants:

Value Description
CreateDatabase Specifies that the SQL Server CE database must first be created then the subscription contents are obtained from the publisher over the network. In this case, the AddSubscription and Synchronize method calls create the SQL Server CE database and download the database contents from the SQL Server Publisher.
ExistingDatabase Specifies that the database already exists, but contents are obtained from the publisher over the network. In this case, the AddSubscription and Synchronize method calls create the SQL Server CE subscription and download the database contents from the SQL Server Publisher.

AddOption only affects how the SQL Server CE database is initially created and treated by the SQL Server CE Client Agent; therefore, determining what data is downloaded to the Windows CE device from the server.

Example

[Visual Basic, C#] This example creates a new subscription database by passing the CreateDatabase value of AddOption when calling the AddSubscription method.

  [Visual Basic] 
Dim repl As SqlCeReplication = Nothing

Try
   ' Set the Replication object
   repl = New SqlCeReplication()
   repl.InternetUrl       = "<http://www.northwindtraders.com/sqlce/sscesa20.dll>"
   repl.InternetLogin     = "MyLogin"
   repl.InternetPassword  = "<password>"
   repl.Publisher         = "MyPublisher"
   repl.PublisherDatabase = "MyPublisher Database"
   repl.PublisherLogin    = "MyPublisher Login"
   repl.PublisherPassword = "<password>"
   repl.Publication       = "MyPublication"
   repl.Subscriber        = "MySub"
   repl.SubscriberConnectionString = "Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;Data Source=\ssce.sdf"
   
   ' Create the Local SSCE Database subscription
   repl.AddSubscription(AddOption.CreateDatabase)
   
   ' Synchronize to the SQL Server 2000 to populate the Subscription 
   repl.Synchronize()

Catch e As SqlCeException
' Use your own error handling routine to show error information.
' ShowError.ShowErrors(e);

Finally
   ' Dispose of the Replication Object
   repl.Dispose()
End Try

[C#] 

        SqlCeReplication repl = null;

        try {
            // Set the Replication object
            repl = new SqlCeReplication();
            repl.InternetUrl       = "<http://www.northwindtraders.com/sqlce/sscesa20.dll>";
            repl.InternetLogin     = "MyLogin";
            repl.InternetPassword  = "<password>";
            repl.Publisher         = "MyPublisher";
            repl.PublisherDatabase = "MyPublisher Database";
            repl.PublisherLogin    = "MyPublisher Login";
            repl.PublisherPassword = "<password>";
            repl.Publication       = "MyPublication";
            repl.Subscriber        = "MySub"; 
            repl.SubscriberConnectionString = "Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;Data Source=\\ssce.sdf";

            // Create the Local SSCE Database subscription
            repl.AddSubscription(AddOption.CreateDatabase);

            // Synchronize to the SQL Server 2000 to populate the Subscription 
            repl.Synchronize();
        }
   
        catch(SqlCeException) {
            // Use your own error handling routine to show error information.
        }

        finally {
            // Dispose of the Replication Object
            repl.Dispose();
        }

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: .NET Compact Framework

.NET Framework Security:

See Also

SqlCeReplication Class | SqlCeReplication Members | System.Data.SqlServerCe Namespace

Syntax based on .NET Framework version 1.1.
Documentation version 1.1.1.

Send comments on this topic.

© Microsoft Corporation. All rights reserved.