Share via


Apply 方法 (SqlConnection)

注意:此 API 已經過時。

透過指定的連接將佈建指令碼套用至 SQL Server 資料庫。

命名空間:  Microsoft.Synchronization.Data.SqlServer
組件:  Microsoft.Synchronization.Data.SqlServer (在 Microsoft.Synchronization.Data.SqlServer.dll 中)

語法

'宣告
<ObsoleteAttribute("Use Constructor with SqlConnection and Apply()")> _
Public Sub Apply ( _
    connection As SqlConnection _
)
'用途
Dim instance As SqlSyncScopeProvisioning
Dim connection As SqlConnection

instance.Apply(connection)
[ObsoleteAttribute("Use Constructor with SqlConnection and Apply()")]
public void Apply(
    SqlConnection connection
)
[ObsoleteAttribute(L"Use Constructor with SqlConnection and Apply()")]
public:
void Apply(
    SqlConnection^ connection
)
[<ObsoleteAttribute("Use Constructor with SqlConnection and Apply()")>]
member Apply : 
        connection:SqlConnection -> unit 
public function Apply(
    connection : SqlConnection
)

參數

例外

例外狀況 條件
ArgumentNullException

connection 是 null Nothing nullptr unit null 參考 (在 Visual Basic 中為 Nothing) 。

範例

下列程式碼範例會針對 filtered_customer 範圍建立佈建物件、指定不應該在伺服器資料庫中建立基底資料表,並且指定應該在名為 "Sync" 的資料庫結構描述中建立所有同步處理相關的物件。此程式碼會在 Customer 資料表上定義篩選,這是佈建範圍的一部分。只有符合該篩選的資料列才會同步處理。CustomerContact 資料表上未定義任何篩選,因此,該資料表中的所有資料列都將同步處理。在定義佈建選項之後,便會呼叫 Apply 方法在伺服器資料庫中建立變更追蹤基礎結構,而且佈建指令碼會寫入檔案中。若要在完整範例的內容中檢視這段程式碼,請參閱 HOW TO:設定及執行資料庫同步處理 (SQL Server)

SqlSyncScopeProvisioning serverConfig = new SqlSyncScopeProvisioning(serverConn, scopeDesc);
serverConfig.SetCreateTableDefault(DbSyncCreationOption.Skip);
serverConfig.ObjectSchema = "Sync";

// Specify which column(s) in the Customer table to use for filtering data, 
// and the filtering clause to use against the tracking table.
// "[side]" is an alias for the tracking table.
serverConfig.Tables["Sales.Customer"].AddFilterColumn("CustomerType");
serverConfig.Tables["Sales.Customer"].FilterClause = "[side].[CustomerType] = 'Retail'";

// Configure the scope and change-tracking infrastructure.
serverConfig.Apply();

// Write the configuration script to a file. You can modify 
// this script if necessary and run it against the server
// to customize behavior.
File.WriteAllText("SampleConfigScript.txt",
    serverConfig.Script());
Dim serverConfig As New SqlSyncScopeProvisioning(serverConn, scopeDesc)
serverConfig.SetCreateTableDefault(DbSyncCreationOption.Skip)
serverConfig.ObjectSchema = "Sync"

' Specify which column(s) in the Customer table to use for filtering data, 
' and the filtering clause to use against the tracking table. 
' "[side]" is an alias for the tracking table. 
serverConfig.Tables("Sales.Customer").AddFilterColumn("CustomerType")
serverConfig.Tables("Sales.Customer").FilterClause = "[side].[CustomerType] = 'Retail'"

' Configure the scope and change-tracking infrastructure. 
serverConfig.Apply()

' Write the configuration script to a file. You can modify 
' this script if necessary and run it against the server 
' to customize behavior. 
File.WriteAllText("SampleConfigScript.txt", serverConfig.Script())

請參閱

參考

SqlSyncScopeProvisioning類別

SqlSyncScopeProvisioning 成員

Apply 多載

Microsoft.Synchronization.Data.SqlServer 命名空間