Share via


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 資料庫中的兩個資料表來定義範圍說明,並用它來佈建就地部署的資料庫和 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 命名空間