The Runtime Methods


The runtime methods are, of course, the methods called during the execution of the package and are responsible for either processing the data in buffers or for preparing the component to do so. The PrimeOutput and ProcessInput methods have already been described.

Now, let's put them in context with the other runtime methods in the order that they are called.

PrepareForExecute

This method is almost identical to the PreExecute method and has no common uses. In rare cases, you might need to have all components do timing-based initialization simultaneously, such that certain settings get initialized for all components of a given type before some other processing or initialization occurs in PreExecute. This type of thing is very rare, however, and so PrepareForExecute and its mirror method, Cleanup, are rarely necessary.

PrepareForExecute happens before PreExecute and is provided for doing work before execution that does not require a lot of resources. If a component needs to acquire and hold onto a resource needed during execution, it should do so in PreExecute because it happens closer to execution time. Also, the AcquireConnections method is called on components after PrepareForExecute and before PreExecute; therefore, any work requiring connections should happen in PreExecute. Finally, the buffer manager is not available to components in PrepareForExecute but is available in PreExecute.

PreExecute

PreExecute is called once per Data Flow Task execution and is called right before the PrimeOutput/ProcessInput methods. This method is provided as a way to do any potentially expensive or time-consuming operations, such as allocating memory or preparing data column-to-buffer column mappings. For example, you can use this method to discover which output columns the user has selected for output.

PrimeOutput

PrimeOutput is the method called on components with an asynchronous output to pass the buffer. This method is only called once per Data Flow Task execution and has the following parameters:

  • outputs An integer value containing the count of the outputs

  • outputIDs An array of integer IDs for the output columns

  • buffers An array of PipelineBuffer objects containing the buffers for each of the outputs

Each output on the component gets its own buffer. For example, a component that supports error outputs would receive two buffers, one for the main output and one for the error output. A component with four outputs and one error output receives five buffers.

ProcessInput

This method is called for every buffer on an input and passes the following parameters:

  • inputID An integer value containing the ID of the input Indicates from which input the buffer originates

  • buffer A PipelineBuffer object containing the buffer to be processed

PostExecute

This is the mirror method for the PreExecute and can be used to do any cleanup necessary. Usually, if there are resources you've acquired during PreExecute you'll want to release them here.

Cleanup

This is the mirror method for the PrepareForExecute method and is rarely used.

To better understand how to write custom data flow components, the following samples have been provided. These samples are a little more complex than what you normally see in a book like this, and because the source is quite functional, to better represent a real custom component, it is also fairly verbose. Only the more difficult and interesting sections are covered here. For a full understanding of the code, load it up in Visual Studio and step through it in the debugger.



Microsoft SQL Server 2005 Integration Services
Microsoft SQL Server 2005 Integration Services
ISBN: 0672327813
EAN: 2147483647
Year: 2006
Pages: 200
Authors: Kirk Haselden

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net