次の方法で共有


Apply メソッド

コンストラクターで指定された接続を使用して、準備スクリプトを SQL Server データベースに適用します。

名前空間:  Microsoft.Synchronization.Data.SqlServer
アセンブリ:  Microsoft.Synchronization.Data.SqlServer (Microsoft.Synchronization.Data.SqlServer.dll 内)

構文

'宣言
Public Sub Apply
'使用
Dim instance As SqlSyncScopeProvisioning

instance.Apply()
public void Apply()
public:
void Apply()
member Apply : unit -> unit 
public function Apply()

データベースの準備では、Sync Framework で同期を実行するために必要なメタデータ テーブルとストアド プロシージャを作成します。既存の SQL Server データベースと新しい SQL Azure データベースを使用する場合は、SQL Server データベースのテーブルに基づく同期スコープを定義してから、SQL Server データベースと SQL Azure データベースを準備します。次の例では、社内の SQL Server データベースの 2 つのテーブルに基づくスコープの説明を定義し、それを使用して社内のデータベースと SQL Azure データベースを同期用に準備しています。なお、このコードを実行するには、SQL Azure データベースを作成し、Utility.ConnStr_SqlAzure_Server に適切な接続文字列を指定する必要があります。

SqlConnection onPremiseConn = new SqlConnection(Utility.ConnStr_SqlSync_Server);
SqlConnection azureConn = new SqlConnection(Utility.ConnStr_SqlAzure_Server);

// First provision the on-premise SQL Server database for synchronization.

// Create a scope named "customers" and add tables to it.
DbSyncScopeDescription customersScopeDesc = new DbSyncScopeDescription("customers");

// Definition for Customer.
DbSyncTableDescription customerDescription =
    SqlSyncDescriptionBuilder.GetDescriptionForTable("Sales.Customer", onPremiseConn);

customersScopeDesc.Tables.Add(customerDescription);

// Definition for CustomerContact, including the list of columns to include.
Collection<string> columnsToInclude = new Collection<string>();
columnsToInclude.Add("CustomerId");
columnsToInclude.Add("PhoneType");
DbSyncTableDescription customerContactDescription =
    SqlSyncDescriptionBuilder.GetDescriptionForTable("Sales.CustomerContact", columnsToInclude, onPremiseConn);

customersScopeDesc.Tables.Add(customerContactDescription);

// Create a provisioning object for "customers" and apply it to the on-premise database.
SqlSyncScopeProvisioning onPremiseConfig = new SqlSyncScopeProvisioning(onPremiseConn, customersScopeDesc);
onPremiseConfig.Apply();

// Provision the SQL Azure database from the on-premise SQL Server database.
SqlSyncScopeProvisioning azureCustomersConfig = new SqlSyncScopeProvisioning(azureConn, customersScopeDesc);
azureCustomersConfig.Apply();
Dim onPremiseConn As New SqlConnection(Utility.ConnStr_SqlSync_Server)
Dim azureConn As New SqlConnection(Utility.ConnStr_SqlAzure_Server)

' First provision the on-premise SQL Server database for synchronization.

' Create a scope named "customers" and add tables to it.
Dim customersScopeDesc As New DbSyncScopeDescription("customers")

' Definition for Customer.
Dim customerDescription As DbSyncTableDescription = SqlSyncDescriptionBuilder.GetDescriptionForTable("Sales.Customer", onPremiseConn)

customersScopeDesc.Tables.Add(customerDescription)

' Definition for CustomerContact, including the list of columns to include.
Dim columnsToInclude As New Collection(Of String)()
columnsToInclude.Add("CustomerId")
columnsToInclude.Add("PhoneType")
Dim customerContactDescription As DbSyncTableDescription = SqlSyncDescriptionBuilder.GetDescriptionForTable("Sales.CustomerContact", columnsToInclude, onPremiseConn)

customersScopeDesc.Tables.Add(customerContactDescription)

' Create a provisioning object for "customers" and apply it to the on-premise database.
Dim onPremiseConfig As New SqlSyncScopeProvisioning(onPremiseConn, customersScopeDesc)
onPremiseConfig.Apply()

' Provision the SQL Azure database from the on-premise SQL Server database.
Dim azureCustomersConfig As New SqlSyncScopeProvisioning(azureConn, customersScopeDesc)
azureCustomersConfig.Apply()

参照

参照

SqlSyncScopeProvisioningクラス

SqlSyncScopeProvisioning メンバー

Apply オーバーロード

Microsoft.Synchronization.Data.SqlServer 名前空間