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()
member SaveProperties : unit -> unit 
public function SaveProperties()

注释

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

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

示例

下面的示例说明了如何使用 SaveProperties 方法。

Dim repl As SqlCeReplication = Nothing

Try
    ' Create SqlCeReplication instance
    '
    'NOTE: when possible, prompt users to enter security 
    'credentials at runtime. If you store credentials in a file, 
    'you must secure the file to prevent unauthorized access.
    '
    repl = New SqlCeReplication()
    repl.InternetUrl = "https://www.adventure-works.com/sqlmobile/sqlcesa35.dll"
    repl.InternetLogin = "MyInternetLogin"
    repl.InternetPassword = "<enterStrongPassword>"
    repl.Publisher = "MyPublisher"
    repl.PublisherDatabase = "MyPublisherDatabase"
    repl.PublisherLogin = "MyPublisherLogin"
    repl.PublisherPassword = "<enterStrongPassword>"
    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
    '
    'NOTE: when possible, prompt users to enter security 
    'credentials at runtime. If you store credentials in a file, 
    'you must secure the file to prevent unauthorized access.
    '
    repl = New SqlCeReplication()
    repl.SubscriberConnectionString = "Data Source='Test.sdf'; Pwd='<enterStrongPassword>'"
    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
    //
    //NOTE: when possible, prompt users to enter security 
    //credentials at runtime. If you store credentials in a file, 
    //you must secure the file to prevent unauthorized access.
    //
    repl = new SqlCeReplication();
    repl.InternetUrl = "https://www.adventure-works.com/sqlmobile/sqlcesa35.dll";
    repl.InternetLogin = "MyInternetLogin";
    repl.InternetPassword = "<enterStrongPassword>";
    repl.Publisher = "MyPublisher";
    repl.PublisherDatabase = "MyPublisherDatabase";
    repl.PublisherLogin = "MyPublisherLogin";
    repl.PublisherPassword = "<enterStrongPassword>";
    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
    //
    //NOTE: when possible, prompt users to enter security 
    //credentials at runtime. If you store credentials in a file, 
    //you must secure the file to prevent unauthorized access.
    //
    repl = new SqlCeReplication();
    repl.SubscriberConnectionString = "Data Source='Test.sdf'; Pwd='<enterStrongPassword>'";
    repl.LoadProperties();

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

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

请参阅

参考

SqlCeReplication类

SqlCeReplication 成员

System.Data.SqlServerCe 命名空间