LoadProperties 方法

检索为同步属性存储的所有值,然后用保存的这些值填充 SqlCeReplication 类属性。

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

语法

声明
Public Function LoadProperties As Boolean
用法
Dim instance As SqlCeReplication
Dim returnValue As Boolean

returnValue = instance.LoadProperties()
public bool LoadProperties()
public:
bool LoadProperties()
member LoadProperties : unit -> bool 
public function LoadProperties() : boolean

返回值

类型:System. . :: . .Boolean

注释

若要使 LoadProperties 函数成功,那么,除非 SubscriberConnectionString 中指定的数据库只有一个订阅,否则必须提供所有的 SqlCeReplication 对象属性。如果数据库只订阅一项发布内容,您可以省略以下属性:

如果在没有设置这些属性的情况下调用 LoadProperties,而数据库中存在多个订阅,则对于数据库中的每一个订阅,都会引发一个错误。集合中的每个错误都包含数据库中每个订阅的 PublisherPublicationPublisherDatabase 属性的字符串参数。

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

示例

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

Try
    '
    '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.
    '
    Dim repl As New SqlCeReplication()
    repl.SubscriberConnectionString = "Data Source='Test.sdf'; Pwd='<enterStrongPassword>'"
    repl.LoadProperties()

    repl.Synchronize()
Catch
    ' Handle errors here
End Try
try
{
    //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.
    //
    SqlCeReplication repl = new SqlCeReplication();
    repl.SubscriberConnectionString = "Data Source='Test.sdf'; Pwd='<enterStrongPassword>'";
    repl.LoadProperties();

    repl.Synchronize();
}
catch (SqlCeException)
{
    // Handle errors here
}

请参阅

参考

SqlCeReplication类

SqlCeReplication 成员

System.Data.SqlServerCe 命名空间