偵錯控制流程Debugging Control Flow

SQL Server Data Tools (SSDT)SQL Server Data Tools (SSDT)MicrosoftMicrosoft Integration ServicesIntegration Services 包含您可用於疑難排解 Integration ServicesIntegration Services 封裝中之控制流程的功能及工具。 and MicrosoftMicrosoft Integration ServicesIntegration Services include features and tools that you can use to troubleshoot the control flow in an Integration ServicesIntegration Services package.

  • Integration ServicesIntegration Services 支援容器及工作上的中斷點。 supports breakpoints on containers and tasks.

  • SSISSSIS 設計師」提供執行階段的進度報表。 Designer provides progress reporting at run time.

  • SQL Server Data Tools (SSDT)SQL Server Data Tools (SSDT) 提供偵錯視窗。 provides debug windows.

中斷點Breakpoints

SSISSSIS 設計工具提供 [設定中斷點] 對話方塊,您可以啟用中斷條件,並指定套件的執行暫停之前中斷點可以出現的次數,在此設定中斷點。 Designer provides the Set Breakpoints dialog box, in which you can set breakpoints by enabling break conditions and specifying the number of times a breakpoint can occur before the execution of the package is suspended. 中斷點可以在封裝層級啟用,也可以在個別元件層級啟用。Breakpoints can be enabled at the package level, or at the level of the individual component. 如果中斷條件在工作或容器層級啟用,則中斷點圖示會顯示在 [控制流程] 索引標籤之設計介面的工作或容器旁。如果中斷條件在封裝上啟用,則中斷點圖示會顯示在 [控制流程] 索引標籤的標籤上。If break conditions are enabled at the task or container level, the breakpoint icon appears next to the task or container on the design surface of the Control Flow tab. If the break conditions are enabled on the package, the breakpoint icon appears on the label of the Control Flow tab.

當叫用中斷點時,中斷點圖示會變更,以協助您識別中斷點的來源。When a breakpoint is hit, the breakpoint icon changes to help you identify the source of the breakpoint. 您可以在封裝執行時加入、刪除及變更中斷點。You can add, delete, and change breakpoints when the package is running.

Integration ServicesIntegration Services 提供您可以在所有工作及容器上啟用的十個中斷條件。 provides ten break conditions that you can enable on all tasks and containers. 在 [設定中斷點] 對話方塊中,您可以在滿足下列條件時啟用中斷點:In the Set Breakpoints dialog box, you can enable breakpoints on the following conditions:

中斷條件Break condition 描述Description
當容器收到 OnPreExecute 事件時。When the task or container receives the OnPreExecute event. 即將執行工作時呼叫。Called when a task is about to execute. 工作或容器會在即將執行之前引發此事件。This event is raised by a task or a container immediately before it runs.
當容器收到 OnPostExecute 事件時。When the task or container receives the OnPostExecute event. 在工作的執行邏輯完成之後立即呼叫。Called immediately after the execution logic of the task finishes. 工作或容器會在執行之後立即引發此事件。This event is raised by a task or container immediately after it runs.
當容器收到 OnError 事件時。When the task or container receives the OnError event. 發生錯誤時由工作或容器呼叫。Called by a task or container when an error occurs.
當容器收到 OnWarning 事件時。When the task or container receives the OnWarning event. 當工作處於還不是錯誤但需要警告的狀態時呼叫。Called when the task is in a state that does not justify an error, but does warrant a warning.
當容器收到 OnInformation 事件時。When the task or container receives the OnInformation event. 需要工作提供資訊時呼叫。Called when the task is required to provide information.
當容器收到 OnTaskFailed 事件時。When the task or container receives the OnTaskFailed event. 由工作主機在失敗時呼叫。Called by the task host when it fails.
當容器收到 OnProgress 事件時。When the task or container receives the OnProgress event. 呼叫以更新工作執行相關的進度。Called to update progress about task execution.
當容器收到 OnQueryCancel 事件時。When the task or container receives the OnQueryCancel event. 在可取消執行之工作處理期間的任何時間呼叫。Called at any time in task processing when you can cancel execution.
當容器收到 OnVariableValueChanged 事件時。When the task or container receives the OnVariableValueChanged event. 當變數的值變更時由 Integration ServicesIntegration Services 執行階段呼叫。Called by the Integration ServicesIntegration Services runtime when the value of a variable changes. 變數的 RaiseChangeEvent 必須設為 [true],方可引發此事件。The RaiseChangeEvent of the variable must be set to true to raise this event.

** 警告 *\* 與此中斷點相關聯的變數必須在 容器 範圍定義。** Warning *\* The variable associated with this breakpoint must be defined at the container scope. 如果變數在封裝範圍定義,則中斷點不會出現。If the variable is defined at the package scope, the breakpoint does not get hit.
當容器收到 OnCustomEvent 事件時。When the task or container receives the OnCustomEvent event. 由工作呼叫,以引發自訂工作定義的事件。Called by tasks to raise custom task-defined events.

除可用於所有工作及容器的中斷條件之外,部份工作及容器還包含用於設定中斷點的特殊中斷條件。In addition to the break conditions available to all tasks and containers, some tasks and containers include special break conditions for setting breakpoints. 例如,您可以在「For 迴圈」容器上啟用中斷條件,以設定在迴圈的每個反覆運算開始時暫停執行的中斷點。For example, you can enable a break condition on the For Loop container that sets a breakpoint that suspends execution at the start of each iteration of the loop.

若要加強中斷點的彈性及能力,您可以藉由指定下列選項來修改中斷點的行為:To add flexibility and power to a breakpoint, you can modify the behavior of a breakpoint by specifying the following options:

  • 叫用計數,或執行暫停之前中斷條件出現的最大次數。The hit count, or the maximum number of times that a break condition occurs before the execution is suspended.

  • 叫用計數類型,或指定中斷條件何時觸發中斷點的規則。The hit count type, or the rule that specifies when the break condition triggers the breakpoint.

    叫用計數會進一步限定「永遠」類型以外的叫用計數類型。The hit count types, except for the Always type, are further qualified by the hit count. 例如,如果類型為「叫用計數等於」而叫用計數為 5 的話,便會在第六次出現中斷條件時暫停執行。For example, if the type is "Hit count equals" and the hit count is 5, execution is suspended on the sixth occurrence of the break condition.

    下表描述叫用計數類型。The following table describes the hit count types.

叫用計數類型Hit count type 描述Description
永遠Always 叫用中斷點時,一律暫停執行。Execution is always suspended when the breakpoint is hit.
叫用計數等於Hit count equals 當中斷點發生的次數等於叫用計數時,暫停執行。Execution is suspended when the number of times the breakpoint has occurred is equal to the hit count.
叫用次數大於或等於Hit count greater than or equal to 當中斷點發生的次數大於或等於叫用計數時,暫停執行。Execution is suspended when the number of times the breakpoint has occurred is equal to or greater than the hit count.
叫用計數倍數Hit count multiple 每當到達叫用計數的倍數時,暫停執行。Execution is suspended when a multiple of the hit count occurs. 例如,若您將此選項設定為 5,則每到達五次叫用便會暫停執行。For example, if you set this option to 5, execution is suspended every fifth time.

設定中斷點To set breakpoints

進度報表Progress Reporting

SSISSSIS 設計工具包含兩種類型的進度報告:[控制流程] 索引標籤之設計介面上的色彩編碼,以及 [進度] 索引標籤上的進度訊息。 Designer includes two types of progress reporting: color-coding on the design surface of the Control Flow tab, and progress messages on the Progress tab.

當您執行封裝時,「 SSISSSIS 設計師」會使用指示執行狀態的色彩來顯示每個工作或容器,以描述執行進度。When you run a package, SSISSSIS Designer depicts execution progress by displaying each task or container using a color that indicates execution status. 您可以根據元素的色彩判斷它是在等候執行、執行中、已順利完成,還是未成功結束。You can tell by its color whether the element is waiting to run, currently running, has completed successfully, or has ended unsuccessfully. 在您停止封裝執行之後,色彩編碼會消失。After you stop package execution, the color-coding disappears.

下表描述用於描述執行狀態的色彩。The following table describes the colors that are used to depict execution status.

ColorColor 執行狀態Execution status
灰色Gray 等候執行Waiting to run
黃色Yellow 執行中Running
綠色Green 執行成功Ran successfully
反白顯示highlighted 執行發生錯誤Ran with errors

[進度] 索引標籤會以執行順序列出工作及容器,並包含開始與完成時間、警告及錯誤訊息。The Progress tab lists tasks and containers in execution order and includes the start and finish times, warnings, and error messages. 在您停止封裝執行之後,進度資訊在 [執行結果] 索引標籤上仍然可用。After you stop package execution, the progress information remains available on the Execution Results tab.

注意

若要啟用或停用 [進度] 索引標籤上的訊息顯示,請在 [SSIS] 功能表上切換 [偵錯進度報表] 選項。To enable or disable the display of messages on the Progress tab, toggle the Debug Progress Reporting option on the SSIS menu.

下圖顯示 [進度] 索引標籤。The following diagram shows the Progress tab.

SSIS 設計工具的 [進度] 索引標籤Progress tab of SSIS Designer

偵錯視窗Debug Windows

SQL Server Data Tools (SSDT)SQL Server Data Tools (SSDT) 包含許多視窗,您可將其用於處理中斷點及偵錯包含中斷點的封裝。 includes many windows that you can use to work with breakpoints, and to debug packages that contain breakpoints. 若要了解每個視窗的詳細資訊,請開啟該視窗並按 F1,以顯示視窗的 [說明]。To learn more about each window, open the window, and then press F1 to display Help for the window.

若要在 SQL Server Data Tools (SSDT)SQL Server Data Tools (SSDT) 中開啟這些視窗,請按一下 [偵錯] 功能表,指向 [視窗],然後按一下 [中斷點]、[輸出] 或 [立即]。To open these windows in SQL Server Data Tools (SSDT)SQL Server Data Tools (SSDT), click the Debug menu, point to Windows, and then click Breakpoints, Output, or Immediate.

下表描述這些視窗。The following table describes the windows.

視窗Window 描述Description
中斷點Breakpoints 列出封裝中的中斷點,並提供啟用及刪除中斷點的選項。Lists the breakpoints in a package and provides options to enable and delete breakpoints.
輸出Output SQL Server Data Tools (SSDT)SQL Server Data Tools (SSDT)中顯示各功能的狀態訊息。Displays status messages for features in SQL Server Data Tools (SSDT)SQL Server Data Tools (SSDT).
立即Immediate 用於偵錯及評估運算式並列印變數值。Used to debug and evaluate expressions and print variable values.

針對工作或容器設定中斷點以偵錯封裝Debug a Package by Setting Breakpoints on a Task or a Container

此程序描述如何在封裝、工作、「For 迴圈」容器、「Foreach 迴圈」容器或「時序」容器中設定中斷點。This procedure describes how to set breakpoints in a package, a task, a For Loop container, a Foreach Loop container, or a Sequence container.

若要在封裝、工作或容器中設定中斷點To set breakpoints in a package, a task, or a container

  1. SQL Server Data Tools (SSDT)SQL Server Data Tools (SSDT)中,開啟包含所需封裝的 Integration ServicesIntegration Services 專案。In SQL Server Data Tools (SSDT)SQL Server Data Tools (SSDT), open the Integration ServicesIntegration Services project that contains the package you want.

  2. 按兩下要在其中設定中斷點的封裝。Double-click the package in which you want to set breakpoints.

  3. 在 [SSIS 設計師] 中,執行下列動作:In SSIS Designer, do the following:

    • 若要在封裝物件中設定中斷點,請按一下 [控制流程] 索引標籤,並將資料指標置於設計介面背景上的任意位置,再以滑鼠右鍵按一下,然後按一下 [編輯中斷點]。To set breakpoints in the package object, click the Control Flow tab, place the cursor anywhere on the background of the design surface, right-click, and then click Edit Breakpoints.

    • 若要在封裝控制流程中設定中斷點,請按一下 [控制流程] 索引標籤,並以滑鼠右鍵按一下工作、「For 迴圈」容器、「Foreach 迴圈」容器或「時序」容器,然後按一下 [編輯中斷點]。To set breakpoints in a package control flow, click the Control Flow tab, right-click a task, a For Loop container, a Foreach Loop container, or a Sequence container, and then click Edit Breakpoints.

    • 若要在事件處理常式中設定中斷點,請按一下 [事件處理常式] 索引標籤,並以滑鼠右鍵按一下工作、「For 迴圈」容器、「Foreach 迴圈」容器或「時序」容器,然後按一下 [編輯中斷點]。To set breakpoints in an event handler, click the Event Handler tab, right-click a task, a For Loop container, a Foreach Loop container, or a Sequence container, and then click Edit Breakpoints.

  4. 在 [設定中斷點 <容器名稱>] 對話方塊中,選取要啟用的中斷點。In the Set Breakpoints <container name> dialog box, select the breakpoints to enable.

  5. 選擇性地修改每個中斷點的叫用計數類型和叫用計數數目。Optionally, modify the hit count type and the hit count number for each breakpoint.

  6. 若要儲存封裝,請按一下 [檔案] 功能表上的 [儲存選取項目]。To save the package, click Save Selected Items on the File menu.

[設定中斷點]Set Breakpoints

使用 [設定中斷點] 對話方塊,即可指定要啟用中斷點的事件並控制中斷點的行為。Use the Set Breakpoints dialog box to specify the events on which to enable breakpoints and to control the behavior of the breakpoint.

選項。Options

已啟用Enabled
選取即可在事件上啟用中斷點。Select to enable a breakpoint on an event.

中斷條件Break Condition
檢視要設定中斷點之可用事件的清單。View a list of available events on which to set breakpoints.

叫用計數類型Hit Count Type
指定中斷點生效的時間。Specify when the breakpoint takes effect.

ReplTest1Value 描述Description
永遠Always 叫用中斷點時,一律暫停執行。Execution is always suspended when the breakpoint is hit.
叫用計數等於Hit count equals 當中斷點發生的次數等於叫用計數時,暫停執行。Execution is suspended when the number of times the breakpoint has occurred is equal to the hit count.
叫用大於或等於Hit greater or equal 當中斷點發生的次數大於或等於叫用計數時,暫停執行。Execution is suspended when the number of times the breakpoint has occurred is equal to or greater than the hit count.
叫用計數倍數Hit count multiple 每當到達叫用計數的倍數時,暫停執行。Execution is suspended when a multiple of the hit count occurs. 例如,若您將此選項設定為 5,則每到達五次叫用便會暫停執行。For example, if you set this option to 5, execution is suspended every fifth time.

叫用計數Hit Count
指定觸發中斷的叫用次數。Specify the number of hits at which to trigger a break. 如果中斷點永遠有效,則無法使用此選項。This option is not available if the breakpoint is always in effect.

另請參閱See Also

套件開發的疑難排解工具Troubleshooting Tools for Package Development
在指令碼工作和指令碼元件中設定中斷點來對指令碼偵錯Debug a Script by Setting Breakpoints in a Script Task and Script Component