共用方式為


ScriptComponent.PreExecute 方法

Executes custom code that must run before the Script component has processed its inputs and outputs.

命名空間:  Microsoft.SqlServer.Dts.Pipeline
組件:  Microsoft.SqlServer.TxScript (在 Microsoft.SqlServer.TxScript.dll 中)

語法

'宣告
Public Overridable Sub PreExecute
'用途
Dim instance As ScriptComponent

instance.PreExecute()
public virtual void PreExecute()
public:
virtual void PreExecute()
abstract PreExecute : unit -> unit  
override PreExecute : unit -> unit
public function PreExecute()

備註

The Script component developer does not use the ScriptComponent class directly, but indirectly, by coding the methods and properties of the ScriptMain class, which inherits from ScriptComponent through the UserComponent class.

The developer can override the PreExecute method to perform any one-time tasks necessary before processing the rows of data.

範例

The following code sample demonstrates how the Script component developer might use the PreExecute and PostExecute methods to open and close a text file connection before and after processing. For more information on this sample, see 以指令碼元件建立目的地.

Imports System.IO
...
Public Class ScriptMain
    Inherits UserComponent

    Dim copiedAddressFile As String
    Private textWriter As StreamWriter
    Private columnDelimiter As String = ","

    Public Overrides Sub AcquireConnections(ByVal Transaction As Object)

        Dim connMgr As IDTSConnectionManager100 = _
            Me.Connections.MyFlatFileDestConnectionManager
        copiedAddressFile = CType(connMgr.AcquireConnection(Nothing), String)

    End Sub

    Public Overrides Sub PreExecute()

        textWriter = New StreamWriter(copiedAddressFile, False)

    End Sub

    Public Overrides Sub MyAddressInput_ProcessInputRow(ByVal Row As MyAddressInputBuffer)

        With textWriter
            If Not Row.AddressID_IsNull Then
                .Write(Row.AddressID)
            End If
            .Write(columnDelimiter)
            If Not Row.City_IsNull Then
                .Write(Row.City)
            End If
            .WriteLine()
        End With

    End Sub

    Public Overrides Sub PostExecute()

        textWriter.Close()

    End Sub

End Class

請參閱

參考

ScriptComponent 類別

Microsoft.SqlServer.Dts.Pipeline 命名空間