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