Tải bản đầy đủ - 0 (trang)
4-3. Accelerating Oracle Data Import

4-3. Accelerating Oracle Data Import

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

Chapter 4 ■ SQL Databases



4.



Click OK and add all the required connection parameters. These are essentially the

same ones described in step 6 of Recipe 4-2. The dialog box should look like Figure 4-6.



Figure 4-6.  Configuring the Attunity connection manager for Oracle

5.



Add a Data Flow task to the SSIS package. Double-click to edit.



6.



Double-click Source Assistant in the SSIS Toolbox.



7.



Select Oracle as the source type in the left pane. Select the connection manager that

you just created in the right pane. The dialog box should look like Figure 4-7.



189

www.it-ebooks.info



Chapter 4 ■ SQL Databases



Figure 4-7.  The SSIS Data Flow Source Assistant

8.



Click OK. An Attunity Oracle source component is added to the Data Flow pane.

Double-click to edit.



9.



Ensure that the required connection manager is selected. Then, select the required

data access mode (Table or SQL command).



10.



Select the table or view—or enter the appropriate SQL SELECT statement. Click OK.



11.



Add a destination component, connect the source to it, and map the columns.

The Data Flow pane should look something like Figure 4-8.



190

www.it-ebooks.info



Chapter 4 ■ SQL Databases



Figure 4-8.  The completed SSIS Data Flow using an Attunity Oracle source

You can now run your Oracle data import.



How It Works

If you are using the Enterprise edition of SQL Server, you can download the Attunity connectors for Oracle, and

use SSIS to achieve much faster data loads than those that are possible using the Oracle connector. You will have

to install an Oracle client on the SQL Server. Use the TNS service name that you configured when setting up the

Oracle client. Otherwise, if anything, the Attunity connector is simpler than the Microsoft or Oracle providers;

and in the tests that I carried out, it is several times faster at loading Oracle data. One interesting aspect is that

you have to use the SSIS Data Flow Source Assistant to create the Attunity data source, and not drag a source

task directly from the SSIS toolbox. Here again (essentially to avoid pointless repetition), I have not gone into

the minutiae of configuring an OLEDB destination. Recipe 1-7 contains an example of an OLEDB destination in

greater detail, should you need it.



Hints, Tips, and Traps





Unlike with SQL Server 2008, you apparently cannot add the Attunity connector to the

SSIS toolbox.







When migrating entire databases, you may find the following resources useful:

www.microsoft.com/sqlserver/en/us/product-info/migration-tool.aspx#Oracle.



4-4. Importing Oracle Data on an “Ad Hoc” Basis

Problem

You want to import data into SQL Server from Oracle over your network without going to the trouble of

developing an SSIS-based solution.



Solution

Use T-SQL and OPENROWSET—or set up a linked server.

The following code will insert data from Oracle into an SQL Server table using OPENROWSET

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



191

www.it-ebooks.info



Chapter 4 ■ SQL Databases



SELECT *

INTO MyOracleTable

FROM OPENROWSET ('OraOLEDB.Oracle', 'MyOracle';'SCOTT';'Tiger',

'select * from SCOTT.EMP');



How It Works

As with the Microsoft Office products described in Chapter 1 (or indeed when accessing data from other SQL

Server instances), you can read and write data on an “ad hoc” basis from Oracle as a data source. To begin, let’s

see how to use OPENROWSET to run an “ad hoc” query. This can be somewhat slow, however, depending on your

environment. So I advise you to test this approach thoroughly to ensure that you can meet your SLAs if you

choose to implement it.

At a minimum, you will need the following:





The Oracle client installed on the SQL Server.







A network connection to the Oracle server (no Firewall issues!).







An Oracle user logon and password with rights to the data you wish to retrieve.







Ad hoc queries enabled on the SQL Server (as described in Recipe 1-4).



There are three elements that make up the OPENROWSET function:





The OLEDB provider (OraOLEDB.Oracle). I am using the Oracle provider.







The connection string ('MyOracle';'SCOTT';'Tiger').







The query ('select * from SCOTT.EMP').



The main thing to note is that the connection string contains (in this order):





The Oracle instance (MyOracle in the example given earlier).







The user ID (SCOTT).







The password (Tiger).



Note that all of these are separated by a semicolon, and the connection string is separated from the query by

a comma.

For more permanent two-way connections to an external database (using OLEDB), a linked server can

frequently be the best answer. To add an Oracle linked server, execute the following code snippet in SQL Server

Management Studio. I have placed all the code that follows this recipe in a single sample file

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

EXECUTE master.dbo.sp_addlinkedserver

@server = 'MyOracleDatabase',

@srvproduct = 'Oracle',

@provider = 'OraOLEDB.Oracle',

@datasrc = 'MyOracle';

EXECUTE master.dbo. sp_addlinkedsvrlogin

@rmtsrvname = 'MyOracleDatabase',

@useself = 'false',

@locallogin = NULL,

@rmtuser = 'SCOTT', -- The Oracle User name

@rmtpassword = 'Tiger'; -- The Oracle User password



192

www.it-ebooks.info



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

4-3. Accelerating Oracle Data Import

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

×