SqlCeReplication.SaveProperties 方法

检索存储在当前订阅的 SqlCeReplication 类属性中的所有值,并将它们存储在系统表中。

命名空间: System.Data.SqlServerCe
程序集: System.Data.SqlServerCe(在 system.data.sqlserverce.dll 中)

语法

声明
Public Sub SaveProperties
用法
Dim instance As SqlCeReplication

instance.SaveProperties
public void SaveProperties ()
public:
void SaveProperties ()
public void SaveProperties ()
public function SaveProperties ()
不适用。

备注

必须在保存同步属性之前成功创建订阅;若要成功调用 SaveProperties,必须提供运行同步所必需的所有参数。如果在保存同步属性时省略了非必需参数,那么,即使已经存在保存的同步属性,这些非必需参数也会设置为默认值。若要避免改写属性,用户应首先检索同步属性,方法是:调用 LoadProperties,更改特定的属性,然后重新保存同步属性。

调用 SaveProperties 时,密码属性的值存储在数据库中。这些值将自动使用唯一的设备硬件密钥进行加密。因此,如果您在一个设备(或一个服务器)上创建订阅配置文件,然后将该数据库复制到一个新设备上,则 LoadProperties 将无法从配置文件检索密码。您可以手动提供正确的密码,然后再次调用 SaveProperties 以保留新设备上的配置文件。

示例

下面的示例显示如何使用 SaveProperties 方法。

Dim repl As SqlCeReplication = Nothing

Try
    ' Create SqlCeReplication instance
    '
    repl = New SqlCeReplication()
    repl.InternetUrl = "https://www.adventure-works.com/sqlmobile/sqlcesa30.dll"
    repl.InternetLogin = "MyInternetLogin"
    repl.InternetPassword = "<password>"
    repl.Publisher = "MyPublisher"
    repl.PublisherDatabase = "MyPublisherDatabase"
    repl.PublisherLogin = "MyPublisherLogin"
    repl.PublisherPassword = "<password>"
    repl.Publication = "MyPublication"
    repl.Subscriber = "MySubscriber"
    repl.SubscriberConnectionString = "Data Source=MyDatabase.sdf"

    ' Store all the properties in the database
    '
    repl.SaveProperties()

    ' In the future all you need to do is load the properties
    '
    repl = New SqlCeReplication()
    repl.SubscriberConnectionString = "Data Source='Test.sdf'; Pwd='<password>'"
    repl.LoadProperties()

    ' Now the SqlCeReplication instance is ready to sync
    '
    repl.Synchronize()

Catch
    ' Handle errors here
Finally
    ' Dispose the repl object
    '
    repl.Dispose()
End Try
SqlCeReplication repl = null;

try
{
    // Create SqlCeReplication instance
    //
    repl = new SqlCeReplication();
    repl.InternetUrl = "https://www.adventure-works.com/sqlmobile/sqlcesa30.dll";
    repl.InternetLogin = "MyInternetLogin";
    repl.InternetPassword = "<password>";
    repl.Publisher = "MyPublisher";
    repl.PublisherDatabase = "MyPublisherDatabase";
    repl.PublisherLogin = "MyPublisherLogin";
    repl.PublisherPassword = "<password>";
    repl.Publication = "MyPublication";
    repl.Subscriber = "MySubscriber";
    repl.SubscriberConnectionString = "Data Source=MyDatabase.sdf";

    // Store all the properties in the database
    //
    repl.SaveProperties();

    // In the future all you need to do is load the properties
    //
    repl = new SqlCeReplication();
    repl.SubscriberConnectionString = "Data Source='Test.sdf'; Pwd='<password>'";
    repl.LoadProperties();

    // Now the SqlCeReplication instance is ready to sync
    //
    repl.Synchronize();

}
catch (SqlCeException)
{
    // Handle errors here
}
finally
{
    // Dispose the repl object
    //
    repl.Dispose();
}

平台

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

Windows Vista、Microsoft Windows XP SP2 和 Windows Server 2003 SP1 支持 Microsoft .NET Framework 3.0。

版本信息

.NET Framework

受以下版本支持:3.0

.NET Compact Framework

受以下版本支持:2.0

请参见

参考

SqlCeReplication 类
SqlCeReplication 成员
System.Data.SqlServerCe 命名空间