SQL Server White Paper Template
Total Page:16
File Type:pdf, Size:1020Kb
Guide to Migrating Sybase Application Interfaces to SQL Server 2008 SQL Server Technical Article Writers: Yuri Rusakov (DB Best Technologies), Alexander Pavlov (DB Best Technologies), Yuri Kovtun (DB Best Technologies) Technical Reviewer: Dmitry Balin (DB Best Technologies) Published: <Month/Year> Applies to: SQL Server 2008 Summary: This white paper describes methods of migrating applications with Sybase interfaces to SQL Server. We cover both Open Standard APIs (ODBC, JDBC, OLE DB, ADO.Net) and proprietary APIs (CT-Library, DB-Library). Created by: DB Best Technologies LLC P.O. Box 7461, Bellevue, WA 98008 Tel.: (408) 202-4567 E-mail: [email protected] Web: www.dbbest.com Copyright This is a preliminary document and may be changed substantially prior to final commercial release of the software described herein. The information contained in this document represents the current view of Microsoft Corporation on the issues discussed as of the date of publication. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication. This White Paper is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS DOCUMENT. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property. Unless otherwise noted, the example companies, organizations, products, domain names, e- mail addresses, logos, people, places and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, email address, logo, person, place or event is intended or should be inferred. © 2010 Microsoft Corporation. All rights reserved. Microsoft and SQL Server are registered trademarks of Microsoft Corporation in the United States and other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners. 2 Contents Copyright ................................................................................................................................... 2 Introduction ................................................................................................................................ 4 Conversion of Open Standard Application Interfaces ................................................................. 5 Overview ................................................................................................................................ 5 JDBC ...................................................................................................................................... 5 ODBC ..................................................................................................................................... 5 OLE DB .................................................................................................................................. 6 ADO.NET ............................................................................................................................... 8 Driver versions ....................................................................................................................... 9 Open Client Libraries to ODBC Migration ..................................................................................11 Overview ...............................................................................................................................11 Main Migration Steps .............................................................................................................11 CT-Library Schema migration ................................................................................................12 Header files mapping .........................................................................................................12 Routine mapping ................................................................................................................12 Type and structure mapping...............................................................................................17 DB-Library Schema migration ................................................................................................20 Overview ............................................................................................................................20 Header files mapping .........................................................................................................20 Routine mapping ................................................................................................................20 Type and structure mapping...............................................................................................25 Other Types of Migration ...........................................................................................................27 Using FreeTDS tool to migrate CT Library and DB Library applications to SQL Server .........27 Migration of Open Client Embedded SQL ..............................................................................27 Migration of ASE Job Scheduler objects ................................................................................28 Conversion of Transact-SQL statements which are embedded in applications ......................28 Conclusion ................................................................................................................................30 About DB Best Technologies .................................................................................................30 3 Introduction DB Best Technologies, Inc. created several white papers which cover migration of databases, such as Oracle or Sybase ASE, to SQL Server 2008. However, in most of the cases there is also a necessity to change database access code in an application connecting to the migrated database. The task is easiest when the application uses a database interface designed to serve many database servers. In this white paper we discuss Open Database Connectivity (ODBC), Java Database Connectivity (JDBC), Object Linking and Embedding Database (OLE DB) and ActiveX Data Objects for .NET (ADO.NET). Migration of such interfaces can be as simple as changing the database driver and/or connection strings. More complicated are the cases when we use proprietary interfaces of one database vendor, which do not provide connectivity to SQL Server 2008. Examples are Sybase ASE CT-Library and DB-Library. In this paper we describe how to change the application code to use SQL Server compatible ODBC interface. 4 Conversion of Open Standard Application Interfaces Overview In this section we discuss methods of redirecting multi-database interfaces of Sybase Adaptive Server Enterprise (ASE) applications to SQL Server 2008. Note that the application code may contain pieces of SQL strings, which are sent to the database and which may not be compatible with SQL Server after the interface was redirected. In such cases, we should convert the embedded SQL according to the rules of SQL conversion. JDBC To convert a JDBC application, we need to change name of loaded JDBC driver class and modify its URL accordingly. Examples: JDBC connection to Sybase ASE: Class.forName(“com.sybase.jdbc.SybDrive”); String url = "jdbc:sybase:Tds:sybase_server_name:5000/test_base”; Connection dbc = DriverManager.getConnection(url, login, password); See below the changes necessary to make this code connect to SQL Server. The class name of SQL Server driver should be specified as a parameter of Class.forName() method, and getConnection method of the loaded class should follow the URL syntax for SQL Server. Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”); String url = “jdbc:sqlserver://sql_server_name:1433”; Connection dbc = DriverManager.getConnection(url, login, password); ODBC ODBC is a universal interface, which means we can change the servers just by specifying another Data Source Name. See below a typical example of switching the database in ODBC connect code. 5 ODBC connection to Sybase: SQLRETURN retcode; SQLHENV env; SQLHDBC dbc; retcode = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env ); retcode = SQLSetEnvAttr( env, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); retcode = SQLAllocHandle( SQL_HANDLE_DBC, env, &dbc ); retcode = SQLConnect(dbc, (SQLCHAR*) "sybase_DataSource_name", SQL_NTS, (SQLCHAR*) "sybase_login", SQL_NTS, (SQLCHAR*) "sybase_password", SQL_NTS); ODBC connection to SQL Server: SQLRETURN retcode; SQLHENV env; SQLHDBC dbc; retcode = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env ); retcode = SQLSetEnvAttr( env, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); retcode = SQLAllocHandle( SQL_HANDLE_DBC, env, &dbc ); retcode = SQLConnect(dbc, (SQLCHAR*)