Happyflystone - 无枪狙击手

No one can go back and make a brand new start.

原创 How to use an ActiveX script task to create a loop in DTS 收藏

新一篇: T-sql 验证身份证算法 | 旧一篇: How to use an ActiveX script task to import data into a new Excel file

Goal
    1. We have a Transfer Data Task between two (2) SQL Servers.
    2. We want this task to run 10 times through a loop.


Real World Example

A database administrator may need to create a testing environment with the destination database being much bigger than the source database, but based on the same type of data. A loop in DTS can be used to accomplish this.

Steps to Implement

    1. In Enterprise Manager, open DTS designer.
    2. Right-click on the white space of the DTS designer and choose Package Properties.
    3. Go to the Global Variables tab and create a new global string variable called count, which will be used to hold the number of times this task will be looped.

 

    4. Click on the symbol in the DTS designer’s connection list to set up the first connection to the source database in your SQL Server.
    5. Click on the symbol in the DTS designer’s connection list to set up the second connection to the destination database in your SQL server.
    6. Highlight the two SQL Server connections and click on the symbol in the DTS designer’s Tasks list so that it will create a Transfer Data Task from the source database to the destination SQL Server database.
    7. From the Tasks list, click on the symbol to add the following ActiveX script task:

 

Function Main()

          
Dim pkg
          
Dim stpbegin

          ‘Increase the count by 
1 after each execution of the Transfer Data Task
          DTSGlobalVariables(
"count").value = DTSGlobalVariables("count").value + 1

          ‘decide 
if we need to loop
          
if DTSGlobalVariables("count").value < 11 then

               
set pkg = DTSGlobalVariables.Parent
               ‘the name of the task can be obtained by 
right click on the task, go to Workflow Properties, then 
               ‘choose the options tab.
               
set stpbegin = pkg.Steps("DTSStep_DTSDataPumpTask_1")
               stpbegin.ExecutionStatus 
= DTSStepExecStat_Waiting

          
end if

          Main 
= DTSTaskExecResult_Success 

End Function

 

    8. Highlight the ActiveX script task and the second SQL server connection; go to the Workflow in the menu and choose “On success” so that this ActiveX script task will be executed before the Transfer Data Task. Here is how it should look:

 

发表于 @ 2008年01月21日 16:18:00|评论(loading...)|编辑|收藏

新一篇: T-sql 验证身份证算法 | 旧一篇: How to use an ActiveX script task to import data into a new Excel file

评论:没有评论。

发表评论  


登录
Csdn Blog version 3.1a
Copyright © 无枪狙击手