Tải bản đầy đủ - 0 (trang)
4-12. Loading Data from Sybase Adaptive Server Enterprise (ASE)

4-12. Loading Data from Sybase Adaptive Server Enterprise (ASE)

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

Chapter 4 ■ SQL Databases



Solution

Use SSMA for Sybase to transfer the data. Take the following steps:

1.



Download the latest version of the SQL Server Migration Assistant for Sybase. It is

currently version 5.2, available at www.microsoft.com/en-us/download/details.

aspx?id=28765.



2.



Install SSMA and the SSMA for Sybase 5.2 extension pack. The latter will ask you for a

server to connect to, as shown in Figure 4-27.



Figure 4-27.  Installing the SSMA extension pack

3.



You will also be asked for a password for the extension pack database master key, as

seen in Figure 4-28.



219

www.it-ebooks.info



Chapter 4 ■ SQL Databases



Figure 4-28.  Defining a password for the SSMA extension pack

4.



The extension pack installation routine will also ask if you want to install the tester

database. I advise you to accept this suggestion, shown in Figure 4-29, if you have the

required privileges.



220

www.it-ebooks.info



Chapter 4 ■ SQL Databases



Figure 4-29.  Installing the SSMA extension pack tester database

5.



Once SSMA and the extension pack are successfully installed, the Installation package

will ask you if you want to install the products on another instance. Unless you do,

click No and Exit. If you examine the databases on the SQL Server instance that you

chose you will see the sysdb database.



6.



Create a new SQL Server database in SSMS named SybaseImport.



7.



Click Start ➤ All Programs ➤ Microsoft SQL Server Migration Assistant for Sybase ➤

Microsoft SQL Server Migration Assistant for Sybase. SSMA will open.



8.



Click File ➤ New Project. Enter the directory where the project will be stored. The

dialog box should look like Figure 4-30.



Figure 4-30.  Creating a new SSMA project



221

www.it-ebooks.info



Chapter 4 ■ SQL Databases



9.



Click the Connect to Sybase button and enter all the required connection parameters

in the dialog box, which should look something like Figure 4-31.



Figure 4-31.  Connecting to Sybase ASE from SSMA

10.



Expand the database that has now appeared in the Sybase Metadata Explorer pane.

Drill down to select the database(s), schema(s), and table(s) whose data you wish to

migrate. With a hint of nostalgia, I am using the pubs2 database. The panel should

look like Figure 4-32.



222

www.it-ebooks.info



Chapter 4 ■ SQL Databases



Figure 4-32.  Selecting Sybase ASE source tables in SSMA for Sybase

11.



Click the Connect to SQL Server button and enter all the required connection

parameters.



12.



Click Databases in the Sybase Metadata Explorer pane. Then click the Convert

Schema button. Note any warning messages.



13.



As we will be transferring data to a database with a different name in SQL Server,

click the Schema (dbo) source in the Sybase Metadata Explorer pane.



14.



In the Sybase Metadata Details pane, ensure that the Schema pane is active.

Click the dbo schema.



15.



Click Modify. The Choose Target Schema dialog box will appear.



16.



Click the Ellipses button. Select the destination database and schema. An example

is shown in Figure 4-33.



223

www.it-ebooks.info



Chapter 4 ■ SQL Databases



Figure 4-33.  Choosing an SQL Server schema in SSMA

17.



Click Select. The Choose Target Schema dialog box will reappear, looking something

like Figure 4-34.



Figure 4-34.  The Choose Target Schema dialog box in SSMA with a new target schema selected

18.



Click OK. The Sybase Metadata Details pane will look something like Figure 4-35.



224

www.it-ebooks.info



Chapter 4 ■ SQL Databases



Figure 4-35.  The SSMA Sybase Schema Metadata pane

19.



Right-click the destination database in the SQL Server Metadata Explorer pane. Select

Synchronize with Database. A dialog box will appear, where you see the objects that

will be created and/or modified in SQL Server (see Figure 4-36).



Figure 4-36.  The SSMA database synchronization dialog box

20.



Click OK.



21.



Select Tools ➤ Project Settings. Then Click General on the bottom left, followed by

Migration. Select Server Side Migration Engine as the migration engine. The dialog

box should look like Figure 4-37.



225

www.it-ebooks.info



Chapter 4 ■ SQL Databases



Figure 4-37.  Selecting server-side migration in SSMA

22.



Click OK to confirm your changes.



23.



Click Migrate Data. The data will be migrated. Then the Data Migration Report dialog

box will appear (see Figure 4-38).



226

www.it-ebooks.info



Chapter 4 ■ SQL Databases



Figure 4-38.  The Data Migration Report dialog box in SSMA

That is it. You have transferred the data from the selected tables into SQL Server from Sybase.



How It Works

As this process can seem rather complex, the following is a high-level overview of what was carried out:





Download and install SSMA for Sybase and the extension pack.







Install the Sybase OLEDB, ODBC, and ADO.NET drivers.







Create an SSMS project and connect to Sybase.







Select the source tables and/or views to migrate.







Convert the schema.







Synchronize with the destination database. This will create any required tables, if they do

not already exist.







Convert the data.



If you have used SSMA for (say) Oracle, then you may feel a certain sense of déjà vu. I nonetheless prefer to

give those readers who are importing data from Sybase a complete import process to follow without presuming

that they have already done this for an Oracle source. Of course, there are many, many variations on the theme

that can be performed when using SSMA. As many of the available possibilities have been described in

Recipe 4-5 (with regards to Oracle) or in Recipe 1-15 (concerning Access), I will not rehash them here, but refer

you to those recipes to complete your knowledge of this product.

We have seen one important new feature of SSMA in this recipe: server-side migration. It is the reason why

the extension pack was installed. It generally makes the transfer of large amounts of data faster because the

data does not go through SSMA, but directly from the Sybase source server to the SQL Server destination. This

also requires that the SQL Server agent be running on the SQL Server destination. You can stick to client-side

processing if you prefer, but you may find it slower.



227

www.it-ebooks.info



s



SSMA can also import data directly to Windows Azure SQL Database, and not just into “classic” SQL

Server databases. All you have to do, when defining the SQL Server connection in step 11, is to supply the

correct Azure database name (for example, recipes.database.windows.net) and the username (for example,

meforprimeminister@recipebook).

The account that is used to connect to ASE must have at least public access to the master database and any

source databases to be migrated to SQL Server or Windows Azure SQL Database. In addition, to select permissions

on tables that are being migrated, the user must have SELECT permissions on the following system tables:





[source_database].databaseo.sysobjects







[source_database].databaseo.syscolumns







[source_database].databaseo.sysusers







[source_database].databaseo.systypes







[source_database].databaseo.sysconstraints







[source_database].databaseo.syscomments







[source_database].databaseo.sysindexes







[source_database].databaseo.sysreferences







master.databaseo.sysdatabases



Hints, Tips, and Traps





There are other versions of Sybase apart from ASE (SQL Anywhere springs to mind), but

in my experience, ASE is the principal source of industrial-strength data that an SQL

Server person may be called to extract data from, so I have only shown this product as a

Sybase data source.







If you need to, you can run the 32-bit version of SSMA, which is available from Start ➤ All

Programs ➤ Microsoft SQL Server Migration Assistant for Sybase ➤ Microsoft SQL Server

Migration Assistant for Sybase (32-bit).







The first time that SSMA runs, it asks for the (free) license key that you must download to

an appropriate directory.







When you save the SSMA project, you will be asked which schemas on the source

database you want to save the metadata for. Choose wisely, or you could be faced with a

very long-lasting process while SSMA gathers all the metadata from the source.







For a list of resources useful in migrating entire databases, take a look at

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



4-14. Importing Sybase ASE Data on an “Ad Hoc” Basis

Problem

You want to import data into SQL Server from Sybase ASE over your network without developing an SSIS-based

solution.



228

www.it-ebooks.info



Chapter 4 ■ SQL Databases



Solution

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

The following code inserts data from Sybase ASE into an SQL Server table using OPENROWSET

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

SELECT *

INTO MySybaseASETable

FROM OPENROWSET ('ASEOLEDB', 'WIN-491Q1DHMHOF:5000';'Adam';'Me4B0ss',

'select au_lname from dbo.authors');



How It Works

The Sybase ASE OLEDB provider is very well-behaved and allows you to import data using OLEDB into SQL

Server using T-SQL. At a minimum, you will need the following:





A functioning network connection to the Sybase ASE server.







The ASEOLEDB provider installed on the SQL Server.







A Sybase ASE 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 (ASEOLEDB).







The connection string ('WIN-491Q1DHMHOF:5000';'Adam';'Me4B0ss'). You have to use

your own connection parameters, of course.







The Query (‘select au_lname from dbo.authors’). Here I am using a standard Sybase

ASE sample database. You can use any database to which you have the appropriate rights.



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





The Sybase ASE instance (WIN-491Q1DHMHOF:5000 in the example provided). Note that

this is the server name (or the Sybase ASE Server name if one was given at installation)

and the port (which you can roughly think of as an SQL Server instance), which was

configured at installation for Sybase ASE.







The user ID (Adam). You will use an appropriate user, of course.







The password (Me4B0ss).



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

query by a comma. Inevitably, you can use INSERT INTO ... SELECT if you prefer, rather than create a table

using SELECT...INTO as I did here.

There are several valid reasons for using OPENROWSET to import data. In no particular order, and without any

pretentions to completeness, they are as follows:





You can use all the power of the SELECT clause to choose the columns to import.







You can filter imported data using a WHERE clause.







You can sort the imported data using an ORDER BY clause.



You can also set up a linked server to Sybase ASE if you want. I’ll explain the easiest way to do this.



229

www.it-ebooks.info



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

4-12. Loading Data from Sybase Adaptive Server Enterprise (ASE)

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

×