20 May 2014

Steps to create event handlers


To add an event handler to the package we've been building, follow these steps:
  • Open SQL Server Management Studio and connect to your test server.
  • Create a new query and select the Chapter16 database in the available databases list on the toolbar.
  • Enter this text into a query window:
  • CREATE TABLE DepartmentExports(   ExportID int IDENTITY(1,1) NOT NULL,    ExportTime datetime NOT NULL CONSTRAINT DF_DepartmentExports_ExportTime DEFAULT (GETDATE()), CONSTRAINT PK_DepartmentExports PRIMARY KEY CLUSTERED  (           ExportID ASC )
  • Click the Execute toolbar button to create the table.
  • Switch back to the Package Designer in BIDS.
  • Select the Event Handlers tab.
  • In the Executable drop-down list, expand the Package node and then the Executables node.
  • Select the Data Flow Task in the Executable dropdown list, click OK.
  • Select the OnPostExecute event handler.
  • Click the hyperlink on the design surface to create the event handler.
  • Drag an Execute SQL task from the Toolbox and drop it on the Package Designer.
  • Double-click the Execute SQL task to open the Execute SQL Task Editor.
  • Select the Chapter16 OLE DB connection manager as the task's connection.
  • Set the SQL Statement property to the following query: 
  • INSERT INTO DepartmentExports (ExportTime)VALUES (GETDATE()) 
  • Click OK to create the event handler.
This event handler will be called when the Data Flow Task finishes executing, and will insert one new row into the tracking table when it is called.

No comments:

Post a Comment