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 を呼び出すと、パスワード プロパティの値がデータベースに格納されます。これらの値は、一意のデバイス ハードウェア キーを使用して、自動的に暗号化されます。そのため、1 つのデバイス (またはサーバー) についてサブスクリプション プロファイルを作成し、そのデータベースを新しいデバイスにコピーすると、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 名前空間