Tải bản đầy đủ - 0 (trang)
4-6. Loading DB2 Data on a Regular Basis

4-6. Loading DB2 Data on a Regular Basis

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

Chapter 4 ■ SQL Databases



2.



Create an SSIS package. Add a new connection manager.



3.



Choose the IBM DB2 for I5/OS IBMDA400 OLEDB Provider.



4.



Enter the fully qualified server name in the Server or File Name field.



5.



Enter the DB2 logon information in the Connection Manager dialog box (see Figure 4-12).



Figure 4-12.  Configuring an OLEDB source for DB2 in SSIS

6.



Select the initial catalog from the list of those available.



7.



When defining an OLEDB source using this connection manager, set the data

access mode as SQL command, and write a select statement to select data, using the

appropriate schema.



8.



Add an OLEDB destination, connect the source to it, and edit the destination.



9.



Define the destination database and table, and map the columns.



199

www.it-ebooks.info



Chapter 4 ■ SQL Databases



How It Works

In this recipe I am assuming that you already know SSIS fairly well, and am concentrating on the interesting new

aspect—the DB2 connection. In reality, linking to a DB2 database is essentially a question of choosing the correct

OLEDB provider and drilling through via the catalog (the database in DB2-speak) to the schema and table. The

good news with DB2 is that it makes connectivity easier in at least two respects:





There is no full-fledged client software to install, only the DB2 provider.







There is no connectivity information to configure in external files (as is the case with

TNSNames.ora in Oracle).



However, DB2 compensates for this level of simplicity with the choice of available OLEDB providers

(depending on which environment you are connecting to), and the mind-numbing complexity of the connection

strings when using T-SQL connectivity. And this is without looking at DB2 Connect (for mainframes), as the

subject is simply too vast. So the hard part when faced with DB2 data sources is probably choosing the appropriate

provider. In this recipe, I am presuming that you are connecting to DB2 on an AS400, using a correctly installed

IBM DB2 for I5/OS IBMDA400 OLEDB Provider. As was the case with an Oracle connection, you could well

find that a helpful and dynamic DB2 DBA can be of invaluable assistance and guide you in the choice of the

appropriate driver.



■■Note  Many – if not all – the DB2 OLEDB providers do not allow the use of parameterized queries. One solution

to this conumdrum is to build the SQL with a Script task, and then pass the SQL out to an SSIS variable which is used

in an OLEDB source.

Should you choose to use the Microsoft OLEDB provider for DB2 with SSIS, then you will find that things are

nearly the same as those described previously using the IBM OLEDB provider for DB2. This means that at step 4,

you will see the Connection Manager dialog box shown in Figure 4-13, and not the IBM dialog box.



200

www.it-ebooks.info



Chapter 4 ■ SQL Databases



Figure 4-13.  Configuring the Microsoft OLEDB Provider for DB2

If you click the “Data Links” button you can define extended data link properties, such as the initial catalog

(database) and schema, as shown in Figure 4-14.



201

www.it-ebooks.info



Chapter 4 ■ SQL Databases



Figure 4-14.  Configuring the Data Link Properties of the MS OLEDB Provider for DB2

If you will be using the IBM OLEDB provider, then you may well end up needing to use ODBC, and so to set

up an ODBC System DSN (data source name). Creating a DSN is discussed in Recipe 4-10, so Figure 4-15 shows

only the configuration panel for the IBM DB2 ODBC provider.



202

www.it-ebooks.info



Chapter 4 ■ SQL Databases



Figure 4-15.  The configuration panel for the IBM DB2 ODBC provider



Hints, Tips, and Traps





When adding the DB2 SQL SELECT statement, you might want to use the DB2 statement

FOR READ ONLY—it is roughly equivalent to T-SQL’s WITH (NOLOCK).







Just as was stated previously for Oracle data sources, you are probably better-off defining

the Connection Managers for both source and destination at package-level when using

SQL Server 2012.



4-7. Importing DB2 Data Without SSIS

Problem

You want to import DB2 data without the challenge of creating an SSIS package.



Solution

Set up a linked server connection to DB2. This is the code to do it

(C:\SQL2012DIRecipes\CH02\MSDB2LinkedServer.sql):

USE master;

GO

EXECUTE master.dbo.sp_MSset_oledb_prop N'IBMDA400', N'AllowInProcess', 1 ;

GO

EXECUTE master.dbo.sp_MSset_oledb_prop N'IBMDA400', N'DynamicParameters', 1 ;

GO



203

www.it-ebooks.info



Chapter 4 ■ SQL Databases



EXECUTE master.dbo.sp_addlinkedserver

@server = 'MyDB2Server'

,@srvproduct = 'IBMDA400'

,@provider = 'MSDASQL'

,@datasrc = 'MyDB2' -- DSN, previously defined

,@catalog = 'CALIDRA02'

,@provstr = 'CMT = 0;SYSTEM = adam.calidra.co.uk' ;

EXECUTE master.dbo.sp_addlinkedsrvlogin

@rmtsrvname = N'MyDB2Server'

,@locallogin = NULL

,@useself = N'False'

,@rmtuser = N'Adam'

,@rmtpassword = N'Me4B0ss';



How It Works

Assuming that you will use one of the available OLEDB providers that has been correctly installed, you can set up

a linked server to import data from DB2 using a fairly “classic” script, as provided in this recipe (for the IBM DB2

provider and a previously-defined ODBC DSN).

For the IBM DB2 OLEDB provider, the T-SQL will look something like this

(C:\SQL2012DIRecipes\CH02\IBMDB2LinkedServer.sql):

EXECUTE master.dbo.sp_addlinkedserver

@server = N'DB2',

@srvproduct = N'Microsoft OLE DB Provider for DB2',

@catalog = N'DB2',

@provider = N'DB2OLEDB',

@provstr = N'Initial Catalog = CarSales;

Data Source = DB2;

HostCCSID = 1275;

Network Address = 257.257.257.257;

Network Port = 50000;

Package Collection = admin;

Default Schema = admin;



Hints, Tips, and Traps





See Recipe 4-10 for details about how to set up an ODBC DSN.



4-8. Sourcing Data from MySQL on a Regular Basis

Problem

You have a MySQL database on your network, and you want to carry out regularly scheduled data loads from

this database.



204

www.it-ebooks.info



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

4-6. Loading DB2 Data on a Regular Basis

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

×