Tải bản đầy đủ (.pdf) (10 trang)

Hands-On Microsoft SQL Server 2008 Integration Services part 23 pptx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (481.37 KB, 10 trang )

198 Hands-On Microsoft SQL Server 2008 Integration Services
3. To specify the source from where the task can access the WQL query, you can
choose from the Direct input, File connection, or Variable options. Leave the
Direct Input option selected in the WqlQuerySourceType field.
4. Type in the following query in the WqlQuerySource field and click OK to return
to the task editor.
SELECT ComputerName, EventCode, Logfile, Message, SourceName,
TimeGenerated, Type
FROM Win32_NTLogEvent
WHERE Logfile = 'Application'
AND SourceName = 'SQLISPackage100'
AND Type = 'Error'
AND TimeGenerated > '20100101'
5. In the OutputType field, choose Data Table.
6. In the OverwriteDestination field, choose Overwrite Destination, as you will be
running this test package many times. However, you should choose this option
carefully in the production environment.
7. In the DestinationType field, you can specify to write the data to a file or to
a variable. Choose File Connection in this field (see Figure 5-22).
8. In the Destination field, choose <New Connection…> and select C:\SSIS\
RawFiles\ApplicationLog.txt as the existing file in the File Connection Manager
Editor. This is a blank file used as a placeholder for Application Log data
Figure 5-21 The WMI Connection Manager configured to connect to CIMV2
Chapter 5: Integration Services Control Flow Tasks 199
enclosed within the folder. If you don’t find this file, create a blank text file in this
folder using Notepad. Click OK twice to complete the configurations.
9. Press  to start debugging the package. If you have not made any typos and the
WQL configured is compatible with your system, the task will run successfully.
Explore to the C:\SSIS\RawFiles folder and open the ApplicationLog.txt file; you
will see the contents of the Windows Application log extracted in the text format.
Review


In this exercise, you learned how to configure and use the WMI Data Reader task. You
also learned about some basic concepts and terminology related to WMI. Developers
use Visual Basic scripting to exploit benefits of WMI. However, while scripting for
WMI, keep in mind that the different versions of Windows operating system have
Figure 5-22 Configuring the WMI DataReader task to read an application log
200 Hands-On Microsoft SQL Server 2008 Integration Services
different sets of WMI classes in the repository. Using the WMI Data Reader task, you
can harness the benefits of WMI yet avoid VB scripting using much simpler WQL
language to write queries. One example could be building a workflow within your
packages based on the environment conditions; for instance, you might want to check
available free memory or free space on your hard disk at run time and build precedence
constraints accordingly. The following two sample queries check the freespace on the
disk or free available memory.
SELECT FreeSpace FROM Win32_LogicalDisk WHERE DeviceID = 'C:'
SELECT FreePhysicalMemory FROM Win32_OperatingSystem
Selecting OutputType as the Property value and the DestinationType as the Variable
in the WMI Data Reader Task Editor will allow you to capture the value to a variable.
Later, you can use this variable in creating an evaluation expression within precedence
constraints to decide whether to continue or stop or divert the workflow to a different
branch within the package. This is quite underutilized yet a powerful feature that allows
you to test the environment conditions at run time and automatically run different
branches based on the results of the WQL queries. Refer to Microsoft SQL Server 2008
Books Online to see more examples of the WQL queries that can be used with this task.
WMI Event Watcher Task
Using the WMI Event Watcher task, you can configure your SSIS package to watch
for an event and, based on the event occurrence, decide whether to run the package or
raise an alert using underlying WMI technology. This is a powerful feature, though it
requires your skills to write WQL event queries to specify the events you want to watch
for. You can use this task in situations such as the following:
To check for availability of enough resources (disk space, memory, and so on) on

c
the computer system before running the package
To watch for files being added to a folder before starting the package
c
To wait for an e-mail (from another package) to arrive with particular subject c
before initiating the processing of the SSIS package
To wait for memory to be available before starting another process
c
Here is the step-by-step procedure to configure this task:
1. After you have placed this task on the Designer panel and started editing, you can
specify a name and description for the task on the General page.
2. On the WMI Options page, specify a WMI Connection Manager in the
WmiConnection field.
Chapter 5: Integration Services Control Flow Tasks 201
3. Specify the source from which the task can read the WQL query in the
WqlQuerySourceType field by selecting from the available options, Direct Input,
File Connection, or Variable. Depending on your choice, the WqlQuerySource
field changes. For example, when you choose Direct Input, you can specify the
WQL query in the WqlQuerySource field.
4. In the ActionAtEvent field, you can specify the action the task should take when
the event occurs. You can choose only to log the event notification and the status
after the event, or you can choose to fire an SSIS event with the event notification
and the status logged after the event (see Figure 5-23).
Figure 5-23 Configurations of the WMI Event Watcher task
202 Hands-On Microsoft SQL Server 2008 Integration Services
5. In the AfterEvent field, you can specify how the task should respond after the
event. The task can be configured to return with success or failure depending on
the outcome of the task, or you can configure the task to watch the event again.
6. The next two options, ActionAtTimeout and AfterTimeout, specify how the task
should behave and respond when the WQL query times out.

7. In the NumberOfEvents field, you can specify the number of times the task
should watch for the event.
8. Lastly, specify the time-out setting for the WQL query in seconds.
Transfer Database Task
The Transfer Database task transfers a database from the source SQL Server to the
destination SQL Server; you can copy or move your database. This task can use the
DatabaseOnline or DatabaseOffline method of transfer. When you choose online
transfer of the database, the source database stays online even during transfer and
can respond to user queries; in the offline method, the source database is detached
and the database files are copied over to the destination server. When using the
DatabaseOffline method, you can specify to reattach the source database or leave
it offline. The user who runs this task to transfer a database must be a member of
sysadmin server role in either offline or online mode; however, if you are using online
mode, the database owner (dbo) role is sufficient to transfer the database.
You can configure the Transfer Database task in the following ways:
e Transfer Database task has three pages: General, Databases, and Expressions.
c
You specify a name and description in the General page.
On the Databases page, specify a SourceConnection and a DestinationConnection
c
to the source and destination servers using the SMO Connection Manager in the
Connections section.
Specify the Action from the drop-down list to copy or move the database and
c
select the DatabaseOnline or DatabaseOffline transfer method in the Method
field. en choose the database you want to transfer from the drop-down list
provided in the SourceDatabaseName field. If using DatabaseOffline method,
you’ll need to specify the files for the database in the SourceDatabaseFiles field
and a True or False value in the ReattachSourceDatabase field (see Figure 5-24).
In the Destination Database section, specify the appropriate values in the

c
DestinationDatabaseName and the DestinationDatabaseFiles fields. Finally, you
can choose to overwrite the files if they exist at the destination.
Use the Expressions page to modify any property at run time using property
c
expressions.
Chapter 5: Integration Services Control Flow Tasks 203
Transfer Error Messages Task
The Transfer Error Messages task copies one or more SQL Server user-defined error
messages from one SQL Server to another. Once you define error messages on one
SQL Server for your application, you might like to make those error messages available
at all the servers wherever you install your application. This task helps avoid the rework
in creating these error messages. You create the error messages on the first server by
using the sp_addmessage stored procedure and use this task to copy the defined error
messages to the remaining servers. These messages can be viewed using the sys.messages
catalog view.
Figure 5-24 Configurations for the Transfer Databases task
204 Hands-On Microsoft SQL Server 2008 Integration Services
You can configure the task as follows:
1. The Transfer Error Messages task editor has three pages—General, Messages, and
Expressions. Specify a name and a description for this task in the General page.
2. In the Messages page, specify a SourceConnection and DestinationConnection
to the source and destination servers using the SMO Connection Manager in the
Connections section.
3. You can choose FailTask, Overwrite, or Skip in the If ObjectExists field; in case
the error message already exists at the destination server (see Figure 5-25).
Figure 5-25 Configuration options for the Transfer Error Messages task
Chapter 5: Integration Services Control Flow Tasks 205
4. Then you can choose to transfer all error messages by selecting True in the
TransferAllErrorMessages field. If you intend to transfer a subset of the

messages, you will select False in this field, in which case, the ErrorMessagesList
and ErrorMessageLanguagesList fields become available to you. Specify the
error messages you want to transfer by selecting from the collection in the
ErrorMessagesList field. You can also select the languages for which you want to
transfer user-defined error messages in the ErrorMessageLanguagesList field.
5. Use the Expressions page to modify any property at run time using property
expressions.
Transfer Jobs Task
The Transfer Jobs task copies SQL Server Agent jobs from the source SQL Server
instance to the destination SQL Server instance. This task uses the SMO Connection
Manager to connect to the source and destination SQL Server instances. The task is
quite straightforward to configure as explained here:
1. Open the editor window for the task and specify the name and description in the
General page.
2. Most settings are configured in the Jobs page. Specify a SourceConnection and
a DestinationConnection to connect to source and destination servers using the
SMO Connection Manager in the Connections section.
3. In the Jobs area, you can specify to copy all the jobs to the destination SQL
Server or select from the list provided in the JobsList field. The selected jobs will
be displayed as a collection in the field (see Figure 5-26).
4. After selecting the jobs you want to transfer, you can fail the task, overwrite, or
skip the jobs if jobs of the same name already exist on the destination SQL Server
using the If ObjectExists field.
5. You can also choose to enable the jobs at the destination SQL Server using
EnableJobsAtDestination field.
6. As with other tasks, you can use the Expressions page to modify any property at
run time using property expressions.
206 Hands-On Microsoft SQL Server 2008 Integration Services
Transfer Logins Task
The Transfer Logins task allows you to copy logins from the source SQL Server

instance to the destination SQL Server instance. You can choose to transfer all the
logins on the server or the selected logins on the server or all the logins for the selected
databases. The following steps explain the configurations of this task:
1. Specify a name and description in the General page.
2. Specify a SourceConnection and a DestinationConnection to connect to source and
destination servers using the SMO Connection Manager in the Connections section.
Figure 5-26 Configuration options for the Transfer Jobs task
Chapter 5: Integration Services Control Flow Tasks 207
3. In the Logins section, choose from the three options to specify the logins you
want to transfer in the LoginsToTransfer field:
AllLogins Choose to transfer all logins from the source SQL Server instance to the
destination SQL Server instance. When you select this option, the subsequent
two fields LoginsList and DatabasesList are disabled.
SelectedLogins Choose to transfer only the selected logins from the source SQL Server
instance to the destination SQL Server instance. When you select this option,
the LoginsList field becomes available and you can select the logins to
transfer from the list provided in this field (see Figure 5-27).
AllLoginsFromSelectedDatabases Choose this option to transfer all the logins from the selected databases.
When you select this option, the DatabasesList field becomes available and
you can select the databases from the list provided in this field for which you
want to transfer the logins.
4. Finally, in the Options area, you can choose to fail the task, overwrite the
logins, or skip the logins if they already exist in the destination server using
the If ObjectExists field. You can also choose to copy the SIDs associated with
the logins to the destination SQL Server instance using the CopySids field.
As you may know, each login is assigned a unique security identifier in SQL
Server. The database users are then linked to SQL Server logins using these
SIDs. When you transfer a database to a different server, the database users get
transferred with the database, but their associated logins are not transferred, as
logins do not reside in the database context and creating new logins even with

the same name on the destination server would not help as the newly created
logins will be getting their own SIDs. To map logins on the destination server
with database users, you will need their SIDs. So, when you transfer a database
using Transfer Database task and subsequently use this task to transfer logins
associated with the transferred database users, you must set the CopySids
property to True so that the transferred database users can be mapped to the
transferred logins. If you do not set the CopySids value to True, the destination
server will assign new SIDs to the transferred logins and the database will not
be able to map users to these logins.
5. You can use the Expressions page to modify any property at run time using
property expressions.

×