Tải bản đầy đủ - 0 (trang)
15-15. Logging Counters from SSIS

15-15. Logging Counters from SSIS

Tải bản đầy đủ - 0trang

Chapter 15 ■ Logging and auditing



1.



Create the Log_ProcessCounters table and the pr_LogCounters stored procedure

described in Recipe 15-14.



2.



Open the Variables pane by right-clicking in the Control Flow pane and selecting

Variables.



3.



Click the Add Variable button and give the variable a name. Ensure that it is

an integer of sufficient size. For the purposes of this recipe, I will use the name

NumberOfRecordsHandled.



4.



Add a Data Flow task, and double-click to edit.



5.



Add a Source component, configured to connect to any valid source. I will use the

CarSales database and the Clients table.



6.



Add a Row Count task to the Data Flow pane. Connect the source component to it.



7.



Double-click the Row Count task to edit it.



8.



Select the variable you just created from the list of variables in the Variable property.

You should end up with something like that shown in Figure 15-7.



Figure 15-7. Selecting a variable for a Row Count task

9.



Click OK.



10.



Add a destination component, configured to use any valid SQL Server destination

database. I suggest the CarSales_Staging database and the Client stable, as given in

Appendix B.



11.



Connect the Rowcount task to the destination component. Double-click the

destination component and map the columns.



12.



Select the Control Flow pane, and add an Execute SQL task onto the Control Flow

after the last task to execute (the Data Flow task in this example). Connect the

preceding task to this new task.



13.



Double-click to edit the Execute SQL task, and add or create an ADO.NET connection.

Name it LogCounters. Connect to the server and database where you will be logging

the counter.



894

www.it-ebooks.info



Chapter 15 ■ Logging and Auditing



14.



15.



Click Parameter Mapping in the left-hand pane of the dialog box, and set the

following parameters:



Variable Name



Direction



Data Type Parameter Name



System::MachineName



Input



String



@MachineName



System::PackageName



Input



String



@PackageName



System::UserName



Input



String



@UserName



User::NumberOfRecordsHandled



Input



Int32



@Counter



Set the following as the SQL statement:

EXECUTE CarSales_Logging.log.pr_LogCounters 'SourceData', 'Rows added to myTable',

@Counter, @PackageName, 'Insert Data', @UserName, @MachineName



16.



Click OK to confirm your modifications.



When you run this package, the counter that stored the number of rows recorded by the SSIS user variable is

written to the log table.



How It Works

When running an SSIS task, you will probably need to log essential counters, which could include input rows,

output rows, and errorrows.

Counters can be logged to an SQL Server table, a text file, or an XML file. They can be logged either as the

process executes or at the end of the package. This approach captured row counts during process execution and

then wrote them to a destination table.

Counter logging is as simple as adding a Row Counter task inside an SSIS Data Flow task—be it a Data

Flow source, Data Flow transformation, and so forth. The Row Counter will record the number of rows that pass

through the data pipeline at the point where the Row Counter task is situated.



Hints, Tips, and Traps





If you wish to record several counters, then each must be defined as a separate variable.

You can, however, write all your counters to the log table as part of a single Execute SQL

task in which you call the pr_LogCounters stored procedure many times. In this case, you

must remember to set all the “counter” variables as parameters in this task.







Remember that SSIS variable scope can trap the tired or unwary programmer. It is

probably better to set all the user-defined variables at package-level (by clicking the

Control Flow pane before defining them) if you wish to avoid wasting plenty of time on

particularly annoying debugging.







You can use an OLEDB connection manager if you prefer, but this requires the use of

positional parameters that I personally find very wearing, and so I can only encourage

you to use ADO.NET connection managers. As you will be writing at most only a few

records to SQL Server, any speed differences between the two connection managers are

simply not an issue.



895

www.it-ebooks.info



Chapter 15 ■ Logging and Auditing







If all the parameters that you are passing to the stored procedure are SSIS variables,

then you can set IsQueryStoredProcedure to True in the Execute SQL task named

LogCounters. You then use only the stored procedure name (log.pr_LogCounters) as the

SQL Statement.



15-16. Creating an SSIS Catalog

Problem

You want to take advantage of the possibilities made available in SQL Server 2012 to store and run SSIS packages

from an SQL Server database.



Solution

Create an SSIS catalog and deploy an SSIS project to it.

1.



In SSMS, right-click Integration Services Catalogs, and select Create Catalog.



2.



Add a password for the encryption key that protects the database.



3.



Click OK.



4.



Expand Integration Services Catalogs, Right-click SSISDB and choose Create Folder.



5.



Enter a folder name and click OK.



You have now created an SSIS catalog, so you can deploy an SSIS project to it. This is done as follows:

6.



In SSDT, open a project. Select Project ➤ Properties. The property

Pages dialog box for your project appears as in Figure 15-8.



Figure 15-8.  SSIS project properties



896

www.it-ebooks.info



Chapter 15 ■ Logging and Auditing



7.



Expand Configuration Properties in the left-hand pane and click Deployment. Add

the server to which you will be deploying the project and the Server Project Path. The

dialog box should look like Figure 15-9.



Figure 15-9.  SSIS project properties for deployment

8.



Click OK to finish configuring the project properties.



9.



Deploy your SSIS package by right-clicking project in the Solution Explorer and

choose Deploy.



10.



Click Next if you see the start page.



11.



In the Select Source pane, confirm that the project is the one that you wish to deploy.

The dialog box should look like Figure 15-10.



897

www.it-ebooks.info



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

15-15. Logging Counters from SSIS

Tải bản đầy đủ ngay(0 tr)

×