共用方式為


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 命名空間