64-bit ODBC
64-bit ODBC primer — when to use a 64-bit ODBC driver; ODBC issues on 64-bit Linux, UNIX, and Windows platforms; background information on 64-bit architecture, operating systems and programming models.
Contents
- Introduction
- ODBC on 64-bit platforms
-
Frequently asked questions
- Do I need to use a 32-bit or 64-bit ODBC driver?
- How can I tell whether an application is 32-bit or 64-bit?
- Can I use a 32-bit ODBC driver on 64-bit platforms?
- My database is running on a 64-bit machine. Do I need to use a 64-bit ODBC driver to connect to it?
- How do I know whether my UNIX or Linux ODBC driver is the 64-bit or 32-bit
SQLLEN
orSQLULEN
version? - How do I obtain a 64-bit or 32-bit
SQLLEN
orSQLULEN
Easysoft ODBC driver? - How do I install both a 32-bit and a 64-bit SQL Server ODBC driver on Linux and UNIX?
- How do I install both a 32-bit and a 64-bit Easysoft ODBC driver on Windows?
- Why do I get error "testlib: not found" when installing a 32-bit Easysoft ODBC driver on my 64-bit Linux machine?
- Can I use a 64-bit Easysoft ODBC-ODBC Bridge client with a 32-bit Easysoft ODBC-ODBC Bridge server?
- Can I connect a 64-bit application to a 32-bit ODBC driver and vice versa?
- Which ODBC driver should I use with a 64-bit PHP package?
- I get a segmentation fault when retrieving a
NULL
SQL Server column with 64-bit PDO ODBC. What can I do?
Introduction
32-bit computer hardware is based on a processor capable of manipulating 32 bits (binary digits) of information at a time and using 32 bits to represent memory addresses. 64-bit hardware uses 64 bits to do the same thing. Usually, 32-bit operating systems run on 32-bit hardware, although it is possible to run 32-bit operating systems on some 64-bit computers. 64-bit operating systems run on 64-bit hardware.
Operating systems consist of a kernel (which allocates system resources, launches applications, and manages memory, files, and peripheral devices) and operating system libraries. 32-bit operating systems have a 32-bit kernel. 64-bit operating systems have a 64-bit kernel. Some operating systems, for example Solaris 7.0+ and AIX 5, can boot either a 32-bit or a 64-bit kernel. A 64-bit kernel is required to run 64-bit applications. (On AIX 5, IBM state that 32-bit and 64-bit applications can run with either a 32-bit or 64-bit kernel. However, for applications that use kernel extensions, this is conditional on the support for the extension in both kernels.) An operating system with a 64-bit kernel can also run 32-bit applications.
Operating system libraries are required to build and run applications. To build 32-bit applications, they must be linked to 32-bit system libraries. To build 64-bit applications, they must be linked to 64-bit system libraries.
32-bit applications are compiled such that memory addresses are 32-bit (4 bytes) in size. These applications can directly access up to 4 GB of virtual memory (the memory potentially available for use on a computer, which may be partially simulated by secondary storage such as a hard disk). This virtual memory limit is present regardless of the amount of physical memory installed on the machine. By contrast, 64-bit applications are compiled such that memory addresses are 64-bits (8 bytes) in size and can use more than 4 GB of virtual memory.
64-bit applications require a machine with a 64-bit processor and a 64-bit operating system. 32-bit applications can be run on both 32-bit and 64-bit machines or operating systems. However, only 64-bit applications can take advantage of the 64-bit capabilities of the processor and operating system. Depending on the application, these may include the 64-bit memory addressing and arithmetic capabilities of the processor, as well as increased system resources provided by the operating system.
Advantages of 64-bit computing
A 32-bit processor can handle a 32-bit integer, and a 64-bit processor can handle a 64-bit integer. A 64-bit processor can therefore handle a larger range of integer values. Since memory addresses are integers that specify a location in memory, a processor that can handle more integer values can also handle more memory addresses. (Each byte of memory in a computer must have a unique address so that applications can keep track of and identify the memory.)
On 32-bit machines, memory addresses are 32 bits in length and stored as base-2 numbers. (The base-2, or "binary," number system expresses integer values as combinations of two digits: 0 and 1.) There are approximately 4 billion possible different 32-bit binary numbers (232), which accounts for the 4 GB memory address space limit on machines with a 32-bit processor.
By contrast, a 64-bit processor can theoretically address up to 16 exabytes (EB) (264 bytes) of memory, giving access therefore to practically unlimited memory.
64-bit memory addressing enables applications to store large data sets entirely in memory. This eliminates the performance penalty associated with swapping portions of the data in and out to disk. For example, the increased memory space available on a 64-bit platform enables large databases to be preloaded into memory, improving data access times for database client applications. Memory is accessed hundreds of times faster than disk drives, so replacing I/O access to data with access via memory is extremely beneficial for database performance. Because more database operations can run at memory speed rather than disk speed, 64-bit machines enable databases to scale to support more users.
On 32-bit systems, memory management extensions exist that enable applications to use more than 4 GB of memory. These extensions are Physical Address Extension (PAE) and the Microsoft Windows-only feature Address Windowing Extension (AWE). Databases such as Oracle and SQL Server can take advantage of PAE and AWE to gain access to additional memory beyond their 4 GB limit. One constraint with PAE and AWE, however, is that memory above 4 GB can only be used to store data, it cannot be used to store or execute code. So, for example, the memory is not available to other memory consuming database operations such as caching query plans, sorting, indexing, joins, or for storing user connection information. By contrast, 64-bit machines make memory available to all database processes and operations.
Other memory intensive applications that benefit from running on a 64-bit platform include computer-aided design or computer-aided manufacturing (CAD or CAM), scientific modelling, and other engineering applications. These applications usually perform optimally by holding large amounts of data in memory. Graphics programs will also see performance improvements as they, too, often deal with large amounts of data, especially when rendering 3-D imagery.
In addition, some types of data processing work more efficiently in a 64-bit environment, such as encryption. Most encryption algorithms are based on very large integers—the larger the integers, the more secure the encryption. Encryption applications can take advantage of 64-bit integers and gain a consequent performance boost on 64-bit systems.
For applications that do not need to address memory beyond the 32-bit processor limit of 4 GB, 64-bit machines still provide substantial benefits in terms of processing speed. With a 64-bit processor, each general-purpose register is 64-bits wide and can represent a much larger integer. (A register is high-speed memory within a processor that provides the fastest way for a processor to access data. A general-purpose register is available for any use rather than being reserved for a specific purpose by the processor or operating system.) Programming languages such as C and C++ can perform mathematical operations on 64-bit integers. 64-bit integer types can be contained within a single register on a 64-bit machine (as opposed to a 32-bit machine, where 64-bit numbers have to be split across two 32-bit registers). The register-width difference produces a substantial reduction in resource requirements when performing 64-bit mathematics. Mathematical operations on 64-bit numbers consume fewer registers and require fewer processor instructions on a 64-bit machine than on a 32-bit machine.
Improvements in parallel processing and bus architectures, enable 64-bit machines to support a larger number of processors (up to 64). An increased capacity for processor support means that a single machine has the potential to support more processes, applications, and users.
On Solaris machines, 32-bit applications using standard I/O are limited to 256 file descriptors, which limits the number of open files that the application can maintain. (A file descriptor is an integer used to identify an open file for the purpose of file access.) This limit is present because Solaris machines use a char
type to represent the file descriptors, which can only hold a range values of 0–255. If there are no free file descriptors in the 0-255 range, an I/O error results if the application attempts to open another file. The limit is not applicable to 64-bit applications, which can use up to 2 billion descriptors.
64-bit UNIX and Linux platforms
There are several 64-bit UNIX and Linux platforms, and these are based around different 64-bit processors. For example, Easysoft ODBC drivers are available on the following 64-bit UNIX and Linux platform or processor combinations:
Platform | Processor |
---|---|
AIX | PPC (PowerPC) |
HP-UX | Itanium i64 |
HP-UX | PA-Risc 2 (Precision Architecture-Reduced Instruction Set Computing) |
Irix | MIPS (Microprocessor without Interlocked Pipeline Stages) |
Linux | x86-64 |
Linux | Itanium i64 |
Solaris | SPARC (Scalable Processor Architecture) |
Tru64 UNIX | Alpha |
64-bit operating systems are able to run both 32-bit and 64-bit applications concurrently. To execute correctly, each application requires a number of libraries. However, the file names for the 32-bit and 64-bit versions of these libraries are identical. They must be differentiated from each other in another way. The most common approach is to use separate directories for 32-bit and 64-bit libraries, although the naming convention used for the directory structure differs from system to system.
Linux systems that follow the Filesystem Hierarchy Standard (FHS) place 64-bit libraries in /lib64
and /usr/lib64
. 32-bit libraries remain in /lib
and /usr/lib
. Using lib
for 32-bit libraries enables 32-bit programs to work on 64-bit machines without any changes. Linux distributions that follow the FHS requirements for 32-bit and 64-bit library locations include Fedora, RedHat, and SUSE. For example, on this FHS-conformant Fedora system, the 64-bit version of the GNU C library is located in /lib64
. The 32-version is located in /lib
. The file name is the same for both 64-bit and 32-bit versions. They are separated by their location.
$ file /lib64/libc-2.7.so /lib64/libc-2.7.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, not stripped $ file /lib/libc-2.7.so /lib/libc-2.7.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, not stripped
Solaris and HP-UX (PA-Risc) systems use a similar method to separate 32-bit and 64-bit libraries. However, although these operating systems preserve the existing 32-bit library directory structure, they use a proprietary naming convention for the 64-bit library directory. Solaris uses /usr/lib/sparcv9
(or /usr/lib/64
) for 64-bit libraries and /usr/lib
for 32-bit libraries. HP-UX (PA-Risc) uses /usr/lib/pa20_64
for 64-bit libraries and /usr/lib
for 32-bit libraries.
HP-UX (Itanium) systems use /usr/lib/hpux32
to store 32-bit libraries and /usr/lib/hpux64
to store 64-bit libraries. (PA-Risc based libraries are also present on Itanium HP-UX systems, in the standard locations, /usr/lib
and /usr/lib/pa20_64
.)
Itanium 2 based Linux systems can provide 32-bit support through the Intel Architecture 32-bit Execution Layer (IA-32 EL). IA-32 EL is a software package that translates IA-32 instructions into Itanium instructions. IA-32 EL replaces the less efficient, hardware-based 32-bit support of the original Itanium processor. Linux distributions that support IA-32 EL include Red Hat Enterprise Linux and SUSE Linux Enterprise Server. The directory structure for 32-bit libraries installed under IA-32 EL is /emul/ia32-linux/lib
and /emul/ia32-linux/usr/lib
. 64-bit libraries are installed in /lib
and /usr/lib
.
On AIX systems, most system libraries are hybrid mode archives—a single library archive file that contains both 32-bit and 64-bit versions of its member objects. AIX uses a "_64" file name suffix to separate the 64-bit objects from the 32-bit objects. The name of the 32-bit object remains unchanged. The following command illustrates this naming convention. It lists both 32-bit and 64-bit object modules contained in the standard C library, libc.a
:
$ ar -X 32_64 -t /usr/lib/libc.a frexp.o itrunc.o ldexp.o . . . frexp_64.o itrunc_64.o ldexp_64.o . . .
64-bit Windows platforms
64-bit Windows platforms support both 32-bit and 64-bit applications. On 64-bit Microsoft Windows platforms, 32-bit applications run in the Windows-on-Windows (WOW64) subsytem. WOW64 emulates the 32-bit Windows operating system to allow 32-bit applications to run without modification.
A limitation of WOW64 is that 32-bit processes cannot load 64-bit dynamic-link libraries (DLLs) and 64-bit processes cannot load a 32-bit DLLs. As the Windows system directory contains both the installed applications and their DLLs, it must be separated into a native system directory for 64-bit applications (%windir%\system32
) and a WOW64 directory for the 32-bit applications (%windir%\syswow64
). To enable 32-bit applications to transparently access the WOW64 system directory, the WOW64 layer provides a file system redirector. Attempts to access the %windir%\system32
directory by a WOW64 process are redirected to the %windir%\syswow64
directory.
The Itanium-based versions of Windows use IA-32 EL to support 32-bit applications. IA-32 EL translates processor instructions between the 32-bit and 64-bit instruction sets and cooperates with the WOW64 subsystem to run 32-bit applications.
64-bit macOS platforms
Starting with version 10.4 (Tiger), macOS supports command-line 64-bit executables on Macintosh computers. Version 10.4+ includes both 32-bit and 64-bit versions of the libSystem
library and the Accelerate framework. Other system frameworks, libraries, and plug-ins are 32-bit only. libSystem
provides the standard C runtime environment, input/output routines, maths libraries, and other functionality required by command-line applications and network services. libSystem
does not provide any functionality to allow an application to implement a graphical user interface (GUI). Any application that links with a GUI library is 32-bit on version 10.4.
Starting with version 10.5 (Leopard), macOS supports 64-bit GUI applications on PowerPC G5 and Intel 64 Macintosh computers. Version 10.5 supports 64-bit Cocoa or Objective C applications. Cocoa is an object-oriented application programming interface (API), which provides an integrated set of shared object libraries, a runtime system, and a development environment. The native language for Cocoa is Objective-C, which provides object-oriented extensions to standard C and Objective-C++. Carbon, a collection of C programming interfaces, is not supported for 64-bit applications. Two 64-bit GUI applications shipped with version 10.5: Xcode (Apple's graphical integrated development environment, which is an optional install) and Chess.
Starting with version 10.6 (Snow Leopard), macOS uses a 64-bit kernel (K64) on some Intel 64 Macintosh computers. Version 10.6 shipped with four 32-bit GUI applications: iTunes, Grapher, Front Row, and DVD Player. All other GUI applications were 64-bit.
On macOS, a "64-bit capable" application is one that can be opened in 64-bit mode as well as 32-bit mode. To find out whether a GUI application is 64-bit capable, select the application icon, and then choose File > Get Info. If the application is 64-bit capable, an Open in 32-bit mode option will be present. If Open in 32-bit mode is not present, the application is not 64-bit capable and can only run in 32-bit mode.
On an Intel 64 Macintosh computer, running this command in a Terminal window lists the programs on the computer that can run in 64-bit mode:
locate -0 app/Contents/MacOS/ | xargs -0 file | grep x86_64
On a PowerPC G5 Macintosh computer, use this command instead:
locate -0 app/Contents/MacOS/ | xargs -0 file | grep ppc64
The package file for a 64-bit capable application, contains two versions of the application: a 32-bit and a 64-bit version. To do this, the universal binary format is used, which is the same file format that enables a PowerPC and Intel version of an application to be embedded in single application package.
If an application is run in 64-bit mode, all supporting binaries needed to run the application, including frameworks, libraries, and plug-ins, must be 64-bit capable. If an application is run in 32-bit mode, all supporting binaries must be 32-bit.
macOS allows a 32-bit kernel to run 64-bit applications. Version 10.6+ runs 64-bit capable applications in 64-bit mode regardless of whether it's booting into a 64-bit or 32-bit kernel. The main advantage of booting into a 64-bit kernel is the ability to use more that 32 gigabytes (GB) of RAM.
When booted into a 32-bit kernel, macOS is in "32-bit mode." When booted into a 64-bit kernel, macOS is in "64-bit mode." Initially, the default mode for version 10.6 was 32-bit mode, to enable greater backwards compatibility with existing 32-bit hardware and software. In mid-2010, this was changed so that the default mode for some Macintosh computers (for example, Mac Pros) became 64-bit mode.
64-bit data models
A data model specifies the size of data types imposed by the underlying architecture. It is usually implemented by the operating systems so that multiple data models can be used on the same processor.
In the 32-bit data model (known as the ILP32 model), int, long and pointer (the ILP part of the acronym) data types are 32 bits in length. Because ILP32 lacks 64-bit pointers, the model is inappropriate for use with 64-bit processors, which are able to address large amounts of memory (beyond the 4 GB ceiling imposed by 32-bit systems). By contrast, 64-bit data models provide 64-bit pointers to take advantage of the larger address space provided by 64-bit processors.
The 32-bit (ILP32) and 64-bit (LP64, LLP64, ILP64) data models are shown in the following table. The table shows the size of the data types in bits.
Data types | ILP32 | LP64 | LLP64 | ILP64 |
---|---|---|---|---|
char |
8 | 8 | 8 | 8 |
short |
16 | 16 | 16 | 16 |
int32 |
- | - | - | 32 |
int |
32 | 32 | 32 | 64 |
long |
32 | 64 | 32 | 64 |
long long (int64 ) |
- | - | 64 | - |
pointer |
32 | 64 | 64 | 64 |
The difference between the three 64-bit models (LP64, LLP64, and ILP64) lies in the non-pointer
data types. With two of the three 64-bit data models (LP64 and LLP64), it is no longer valid to assume that int
, long
, and pointer
data types are the same size. Applications whose code makes this assumption often cease to work properly when compiled on a 64-bit platform.
LP64 is the standard data model on 64-bit Linux, UNIX, and macOS systems. In the LP64 model, long
s and pointer
s are 64 bits wide and int
s remain fixed at 32 bits. The advantage of this data model is that it provides 64-bit addressing (64-bit pointer
s), 64-bit arithmetic (64-bit long
s), backward compatibility (most int
s in existing applications can remain as 32 bits in a 64-bit environment) and portability (does not require new data types such as int32
and int64
). The difference in the size of long
and pointer
between ILP32 and LP64 can cause data truncation issues in code that assumes these types are the same width as int
s.
LLP64 is the standard data model on 64-bit Windows systems, and is sometimes described as a 32-bit model with 64-bit addresses. In the LLP64 model, pointer
s are 64 bit; the other types remain unchanged from the ILP32 model. int
or long
variables that need to be 64 bits in length are changed to long long
(also know as int64
), a non-standard data type introduced by the LLP64 model.
ILP64 preserves the relationship between the three basic types that ILP32 developers are used to by making int
, long
, and pointer
types the same size. Converting or assigning pointers to int
or long
does not result in data truncation. The disadvantage of the ILP64 data model is that it depends on a new data type (int32
) for 32-bit int
s. This makes it difficult to write code that can run on both 32-bit and 64-bit platforms without resorting to conditional compilation.
ODBC on 64-bit platforms
Background
In the original ODBC API specification and header files, the SQLINTEGER
and SQLUINTEGER
types, used for passing and returning data buffer lengths, were 32-bit values. In the underlying data model, ILP32, these types are 32-bit long
s. Microsoft subsequently introduced two new types for data buffer arguments, SQLLEN
and SQLULEN
, and changed some ODBC APIs to use the new types. In version 3.52 of the ODBC specification, Microsoft changed the SQLLEN
and SQLULEN
types for 64-bit Windows platforms. On 64-bit Windows, the SQLLEN
and SQLULEN
types were changed from long
s to long long
s. Even though longs are 32-bit in the 64-bit Windows data model, long long
s are 64-bit.
On 64-bit Windows, pointers are 64-bit, which gives 64-bit ODBC applications the potential to take advantage of 64-bit memory addressing. For example, an application could use 64-bit addressing to provide a large buffer for LOB
data. A 32-bit value may not be sufficient to return the length of data in a large buffer on 64-bit platforms. This may be the reason why Microsoft chose to increase the size of the SQLLEN
and SQLULEN
types from 32-bit long
s to 64-bit long long
s.
ODBC on 64-bit Linux and UNIX Platforms
unixODBC Driver Manager
It's possible to build the unixODBC ODBC Driver Manager on 64-bit platforms with either 32-bit or 64-bit SQLLEN
/SQLULEN
types.
unixODBC 2.2.13+
In unixODBC 2.2.13, the default size of SQLLEN
and SQLULEN
types changed from 32 bits to 64 bits. In unixODBC 2.2.13+, the BUILD_LEGACY_64_BIT_MODE
macro in sqltypes.h
controls whether SQLLEN
and SQLULEN
types are 32-bit or 64-bit (the default). To build unixODBC 2.2.13+ with 32-bit SQLLEN
and SQLULEN
types, use CFLAGS
to define BUILD_LEGACY_64_BIT_MODE
before configuring the unixODBC build system. For example:
$ CFLAGS=-DBUILD_LEGACY_64_BIT_MODE=1
$ export CFLAGS
$ ./configure --enable-gui=no --enable-drivers=no
$ make
$ cd exe
$ ./odbc_config --ulen
-DSIZEOF_SQLULEN
=4
$ ./odbc_config --cflags
-DHAVE_UNISTD_H -DHAVE_PWD_H -DHAVE_SYS_TYPES_H -DHAVE_LONG_LONG \
-DSIZEOF_LONG_INT=4 -I/home/myuser/include
The unixODBC source distribution is available to download from the unixODBC web site.
If your application includes sqltypes.h
and you want to use it with a unixODBC 2.2.13+ Driver Manager that is built with 32-bit SQLLEN
and SQLULEN
types, you need to build the application with the same define as the one used when building unixODBC. Alternatively, include the file unixodbc_conf.h
.
You can use unixODBC's odbc_config
program to display information about how unixODBC was built. The unixODBC 2.2.13+ version of odbc_config
supports the --ulen
option, which reports whether the unixODBC Driver Manager was built with 64-bit or 32-bit SQLLEN
and SQLULEN
types. If odbc_config --ulen
displays -DSIZEOF_
, unixODBC was built with 64-bit SQLULEN
=8SQLLEN
and SQLULEN
types. If odbc_config --ulen
displays -DSIZEOF_
, unixODBC was built with 32-bit SQLULEN
=4SQLLEN
and SQLULEN
types.
Note that not all unixODBC distributions include odbc_config
. Note also that odbc_config
only reports information about the unixODBC distribution it was shipped with. For example, you have two copies of unixODBC installed on a machine: one copy built from source, which includes odbc_config
; one copy supplied with the operating system, which does not include odbc_config
. The odbc_config
program cannot be used to provide information about the operating system version of unixODBC.
In unixODBC 2.3+, the odbcinst
program can be used to report whether the unixODBC Driver Manager was built with 64-bit or 32-bit SQLLEN
or SQLULEN
types. In the example output, the Driver Manager that was installed by an Easysoft ODBC driver was built with 32-bit SQLLEN
and SQLULEN
types:
$ cd /usr/local/easysoft/unixODBC/bin $ ./odbcinst -j unixODBC 2.3.0 DRIVERS............: /etc/odbcinst.ini SYSTEM DATA SOURCES: /etc/odbc.ini FILE DATA SOURCES..: /etc/ODBCDataSources USER DATA SOURCES..: /home/myuser/.odbc.iniSQLULEN
Size.......: 4SQLLEN
Size........: 4 SQLSETPOSIROW Size.: 2
Note If your version of unixODBC was built with 32-bit SQLLEN
or SQLULEN
types, you need to use it with an ODBC driver that's been built with 32-bit SQLLEN
or SQLULEN
types. If your version of unixODBC was built with 64-bit SQLLEN
or SQLULEN
types, you need to use it with an ODBC driver that's been built with 64-bit SQLLEN
and SQLULEN
types. (Refer to How do I know whether my UNIX or Linux ODBC driver is the 64-bit or 32-bit SQLLEN
or SQLULEN
version?) If you are using or want to use an Easysoft ODBC driver with an existing version of unixODBC (that is, a version that is not included in the Easysoft driver distribution), refer to How do I know whether my UNIX or Linux ODBC driver is the 64-bit or 32-bit SQLLEN
or SQLULEN
version? and How do I obtain a 64-bit or 32-bit SQLLEN
or SQLULEN
Easysoft ODBC driver for Linux and UNIX platforms?
unixODBC 2.2.12
The default behaviour for unixODBC 2.2.12 is to build the Driver Manager with 32-bit SQLLEN
and SQLULEN
types. The BUILD_REAL_64_BIT_MODE
and SIZEOF_LONG
macros in unixodbc_dist_dir/include/sqltypes.h
determine whether these types are 32-bit (the default) or 64-bit. To build unixODBC 2.2.12 with 64-bit SQLLEN
or SQLULEN
types:
- Download the unixODBC distribution, unpack and
cd
into the directory created by unpacking the distribution file:$ gunzip unixODBC-2.2.12.tar.gz $ tar -xvf unixODBC-2.2.12.tar $ cd unixODBC-2.2.12
- Use the
CPPFLAGS
environment variable to defineBUILD_REAL_64_BIT_MODE
and setSIZEOF_LONG
to8
:$ CPPFLAGS="-DBUILD_REAL_64_BIT_MODE -DSIZEOF_LONG=8" $ export CPPFLAGS
- Configure the unixODBC build system. For example:
$ ./configure --enable-gui=no --enable-drivers=no
For information about unixODBC configure options, refer to our ODBC on Linux and UNIX article. In the example command, the options specify that unixODBC should be built without GUI components or sample ODBC drivers.
The default for the unixODBC 2.2.12 source distribution is to build 32-bit SQLLEN
and SQLULEN
types. However, this does not mean that a unixODBC 2.2.12 package included with a Linux or UNIX distribution will be built with 32-bit SQLLEN
and SQLULEN
types too. For example, on Red Hat, Debian, and Ubuntu Linux distributions, the unixODBC package is built with 64-bit SQLLEN
and SQLULEN
types.
Applications that pass 64-bit values to SQLLEN
and SQLULEN
ODBC API parameters must be used with a version of unixODBC that is built with 64-bit SQLLEN
and SQLULEN
types (and vice versa). If unixODBC is built with 64-bit SQLLEN
and SQLULEN
types, it must be used with an ODBC driver that is built with 64-bit SQLLEN
and SQLULEN
types (and vice versa). If you are using a version of unixODBC that was included in an Easysoft ODBC driver distribution, both ODBC Driver Manager and ODBC driver will be built with the same size SQLLEN
and SQLULEN
types. However, the Easysoft driver installation script gives you the option to use the version of unixODBC included in the operating system distribution rather than the driver distribution. If an Easysoft ODBC driver built with 32-bit SQLLEN
and SQLULEN
types was used with a unixODBC Driver Manager built with SQLLEN
and SQLULEN
types, the results will be unpredictable. Side effects could include data loss, data corruption, or your application crashing.
For example, Oracle DG4ODBC passes 64-bit values to SQLLEN
and SQLULEN
ODBC API parameters, and therefore must be used with a 64-bit SQLLEN
and SQLULEN
ODBC Driver Manager and ODBC driver. To illustrate the potential side effects of not doing this, we used the following application/Driver Manager/driver combinations to retrieve NVARCHAR
SQL Server data from the Northwind Suppliers table:
- DG4ODBC > 64-bit
SQLxLEN
ODBC Driver Manager > 32-bitSQLxLEN
SQL Server ODBC driver. - DG4ODBC > 32-bit
SQLxLEN
ODBC Driver Manager > 32-bitSQLxLEN
SQL Server ODBC driver.
In both cases, we experienced data loss:
SQL> select "ContactName" from Suppliers@sqlsrv2005; ContactName ------------------------------------------------------------ Charlotte Cooper Shelley Burke Regina Murphy Yoshi Nagas Antonio del V Mayumi Ohno Ian Devling Peter Wilson Lars Peterson Carlos Diaz Petra Winkler ContactName ------------------------------------------------------------ Martin Bein Sven Petersen Elio Rossi Beate Vileid ContactName ------------------------------------------------------------ 29 rows selected.
At the time of writing, applications that Easysoft know to have been built with 64-bit SQLLEN
and SQLULEN
types are:
- DG4ODBC
- IBM UniData 7.1.8+
- PHP (CentOS package)
- SAS
iODBC Driver Manager
iODBC is another ODBC Driver Manager that is available for Linux and UNIX platforms (and macOS and Windows). The default for the iODBC source distribution is to build the iODBC Driver Manager with 64-bit SQLLEN
and SQLULEN
types. These types were introduced in the 3.52.1 release of iODBC.
ODBC on 64-bit Windows platforms
On 64-bit Windows platforms, there is both a 32-bit and 64-bit version of the Microsoft ODBC Driver Manager. The 64-bit version (%windir%\System32\Odbc32.dll
):
- Loads and unloads 64-bit ODBC drivers.
- Processes ODBC function calls made by 64-bit applications or passes them to a 64-bit ODBC driver.
The 32-bit version of the Driver Manager (%windir%\SysWOW64\Odbc32.dll
):
- Loads and unloads 32-bit ODBC drivers.
- Processes ODBC function calls made by 32-bit applications or passes them to a 32-bit ODBC driver.
The Driver Manager implements the SQLDrivers
and SQLDataSources
APIs to allow an application to find out what ODBC drivers are installed and what ODBC data sources are defined. The SQLDrivers
API provided by the 64-bit Microsoft ODBC Driver Manager only lists 64-bit ODBC drivers and vice versa. The SQLDataSources
API provided by the 64-bit Microsoft ODBC Driver Manager does not list 32-bit system data sources and vice versa.
On 64-bit Windows platforms, there is both a 32-bit and a 64-bit version of ODBC Data Source Administrator, the application you use to manage ODBC data sources. To run the 64-bit ODBC Data Source Administrator, in the Windows Run dialog box, enter:
odbcad32.exe
To run the 32-bit version of the ODBC Data Source Administrator, in the Windows Run dialog box, enter:
%windir%\syswow64\odbcad32.exe
The 64-bit version of ODBC Data Source Administrator enables you to:
- Add, modify, and delete data sources for 64-bit ODBC drivers.
- Find out which 64-bit ODBC drivers are installed.
- Trace the ODBC API calls that are made by a 64-bit application.
The 32-bit version of ODBC Data Source Administrator enables you to do these tasks for 32-bit ODBC drivers and applications.
A system ODBC data source is accessible to all users on the computer on which it has been defined. On 64-bit Windows platforms, system data sources for 64-bit ODBC drivers are stored in a registry subkey called HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI; system data sources for 32-bit ODBC drivers are stored in a registry subkey called HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI. 64-bit system ODBC data sources are only accessible to 64-bit applications. 32-bit system ODBC data sources are only accessible to 32-bit applications. The WOW64 registry redirector intercepts calls made to certain portions of the registry and redirects them to another portion of the registry. Registry redirection affects the HKEY_LOCAL_MACHINE\SOFTWARE subkey. Registry calls made to this key by 32-bit applications are redirected to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node. So, for example, when a 32-bit application calls SQLDataSources
, the resultant registry call is redirected from HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI, and the only system data sources that are returned are ones for 32-bit ODBC drivers.
The 32-bit Microsoft ODBC Driver Manager will not attempt to load an ODBC driver specified by a 64-bit system data source. If a 32-bit application attempts to connect to a 64-bit system data source, the connection fails with the error:
[Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application
This error occurs irrespective of whether there is also 32-bit version of the ODBC driver specified in data source installed on the computer.
The 64-bit Microsoft ODBC Driver Manager will not attempt to load an ODBC driver specified by a 32-bit system data source. If a 64-bit application attempts to connect to a 32-bit system data source, the connection also fails with the "architecture mismatch" error.
A user data source is only accessible to the user who created it. On 64-bit Windows platforms, user data sources for both 32-bit and 64-bit ODBC drivers are stored in a registry subkey called HKEY_CURRENT_USER\SOFTWARE\ODBC\ODBC.INI. The registry redirector does not affect this key. User data sources are accessible to all ODBC-enabled applications therefore, irrespective of application or driver architecture. For example, the 32-bit and 64-bit versions of ODBC Data Source Administrator list user data sources for both 32-bit and 64-bit ODBC drivers. (To avoid confusion, you can indicate the driver architecture in the data source name, for example, by suffixing the name with _32
or _64
.)
If a 32-bit application attempts to connect to a valid user data source for a 64-bit ODBC driver, the connection will succeed if a 32-bit version of the driver is installed. Otherwise, the connection will fail with the "architecture mismatch" error. For example, Microsoft's SQL Server ODBC driver installs both a 64-bit library (%WINDIR%\System32\sqlsrv32.dll
) and a 32-bit library (%WINDIR%\SysWOW64\sqlsrv32.dll
) on 64-bit Windows platforms. If a 32-bit application attempts to connect to a valid user data source for the 64-bit version of the SQL Server ODBC driver, the connection will succeed. This is because the WOW64 file system redirector loads the 32-bit version of the ODBC driver (in %windir%\SysWOW64
) rather than the 64-bit driver (in %windir%\System32
) specified by the data source.
Similarly, if a 64-bit application attempts to connect to a valid user data source for a 32-bit ODBC driver, the connection will succeed if a 64-bit version of the driver is installed.
As mentioned, on 64-bit Windows, some ODBC drivers install both a 32-bit and a 64-bit version of the driver. For example, Microsoft's SQL Server and SQL Server Native client ODBC drivers; Easysoft's Firebird, InterBase and ODBC-ODBC Bridge drivers. These ODBC drivers can be used with both 32-bit and 64-bit ODBC applications therefore.
On 64-bit Windows, some ODBC drivers are only available as a 64-bit library. For example, Microsoft's ACE-based Access ODBC driver (*.mdb, *.accdb). Some ODBC drivers are only available as a 32-bit library irrespective of the operating system platform. For example, Microsoft's Jet-based Access ODBC driver (*.mdb). (Note that if you attempt to connect a 64-bit application to user data source for the Jet-based Access ODBC driver, the 64-bit ACE-based driver is not transparently loaded. Although both are capable of connecting to an MDB format Access database, they are different drivers with a different file name.)
If an ODBC driver is specified on the connection string, the driver architecture must be the same as the application's. Otherwise, the connection will fail with the error:
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (SQL-IM002)
For example, the preceding error will be returned if a 64-bit application uses a DSN-less connection to connect to Microsoft's Jet-based Access ODBC driver:
DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Users\Public\Downloads\Northwind.mdb;
Windows 8 and later
Starting in Windows 8, both the 32-bit and 64-bit version of the ODBC Data Source Administrator are located in Administrative Tools in Control Panel. The icons for the two versions are labelled something like:
- ODBC Data Sources (32-bit)
- ODBC Data Sources (64-bit)
The User DSN and System DSN tabs in the ODBC Data Source Administrator include a Platform column, which tells you whether a data source can be used with a 32-bit or a 64-bit application or both.
Both versions of the ODBC Data Source Administrator list all installed drivers and available data sources regardless of the driver architecture. If the driver architecture is different to that of the ODBC Data Source Administrator, you cannot use the tool to create, edit, or remove a data source for that driver. For example, to create a system data source for the 32-bit only Microsoft Access ODBC driver, you need to use the 32-bit ODBC Data Source Administrator. This data source will be accessible in the 64-bit ODBC Data Source Administrator but not editable or removable.
Windows PowerShell cmdlets for ODBC
Windows PowerShell is a command-line scripting environment from Microsoft. Built-in Windows PowerShell commands, called cmdlets, enable users to control and automate the administration of the Windows operating system and applications that run on Windows.
Starting in Windows 8, a number of PowerShell cmdlets are provided for listing and managing ODBC drivers and data sources. For example, the Add-OdbcDsn
cmdlet enables an ODBC data source to be added. This sample cmdlet adds a 64-bit system ODBC data source for Easysoft's Derby ODBC driver:
PS C:\> Import-Module Wdac PS C:\> Add-OdbcDsn "64-bit Derby System DSN" -DriverName "Easysoft ODBC-Derby" -DsnType System -Platform 64-bit -SetPropertyValue @("Database=nativedb") -PassThru
Some ODBC cmdlets have a -Platform
parameter, which lets you set the target architecture for the cmdlet.
When listing ODBC drivers (Get-OdbcDriver
) or data sources (Get-OdbcDsn
), -Platform
can be set to 32-bit
, 64-bit
or All
. The default value for -Platform
is All
, and so both 32-bit and 64-bit ODBC drivers and data sources are listed.
When managing ODBC drivers (Set-OdbcDriver
) or data sources (Add-OdbcDsn
, Remove-OdbcDsn
, Set-OdbcDsn
) -Platform
can be set to 32-bit
or 64-bit
. By default, -Platform
matches the architecture of the process in which the cmdlet is being run. For example, if you start a 32-bit PowerShell session by running the icon labelled Windows PowerShell (x86) (which runs a PowerShell executable located in the WOW64 directory), and omit Platform
when adding a data source, your data source will be 32-bit. (Note that you can add 64-bit ODBC data sources or configure 64-bit ODBC drivers from a 32-bit PowerShell process and vice versa.)
ODBCConf
ODBCConf is a Windows command line utility that enables you to install and configure ODBC drivers and configure ODBC data sources.
On 64-bit Windows platforms, there is both a 32-bit and 64-bit version of ODBCConf.
The 32-bit version of the ODBCConf executable (odbcconf.exe
) is located in this folder:
%windir%\SysWOW64
The 64-bit version of the ODBCConf executable is located in folder:
%windir%\System32
If you want to install or configure a 32-bit ODBC driver or configure a data source for a 32-bit ODBC driver, use the 32-bit version of ODBCConf.
If you want to install or configure a 64-bit ODBC driver or configure a data source for a 64-bit ODBC driver, use the 64-bit version of ODBCConf.
Accessing Oracle from 32-bit ODBC applications on 64-bit Windows platforms
The Easysoft Oracle ODBC driver accesses Oracle by using the Oracle database client, which uses Oracle Net to communicate with the database. Some versions of the Oracle Net software fail with the error ORA-12154: TNS:could not resolve the connect identifier specified
if the application with which you're trying to connect is installed in a directory that contains parentheses in its name. This issue affects 32-bit applications on 64-bit Windows platforms because Windows installs 32-bit applications under the drive:\Program Files(x86)
directory.
The Oracle bug report associated with this problem is Bug 3807408 Cannot Externally Authenticate User With Quote In Username (Oracle MetaLink login required).
To fix this problem and therefore enable 32-bit applications to access Oracle through ODBC and Oracle Net, obtain and apply an Oracle patch set that contains a fix for bug 3807408.
If the patch is not available for your version of the Oracle client, you can try working around the problem by starting your application from the command prompt. In the command line, replace Program Files(x86)
; with Progra~2
.
ODBC on 64-bit macOS platforms
Starting with version 10.2 (Jaguar), the iODBC Driver Manager is included with macOS. Source code for each version of iODBC that Apple has shipped with the operating system (starting with macOS 10.3) is available on the Apple Open Source web site. (To access the relevant iODBC web page, choose your version of macOS from the Releases list.)
The iODBC Driver Manager package includes:
- An ODBC Driver Manager.
- A command line application that returns various iODBC configuration details.
- A command line ODBC application for testing ODBC data sources.
Apple also provide ODBC Administrator (Applications > Utilities > ODBC Administrator), a GUI application for managing ODBC data sources. ODBC Administrator lets you:
- Add, modify, and delete user and system data sources.
- Find out which ODBC drivers are installed.
- Trace the ODBC API calls an application makes.
- Enable iODBC connection pooling, a mechanism that can speed up connection times for applications that run continuously, but repeatedly close and reopen the same connection.
Note Starting with macOS version 10.6 (Snow Leopard), ODBC Administrator is no longer shipped with the operating system and must be downloaded and installed separately. ODBC Administrator is available to download from the Apple Support web site as a Disk Image file (.dmg
).
macOS packages containing more recent versions of iODBC than the one provided by Apple can be downloaded from the iODBC web site:
- The iODBC Replacement SDK for
/usr
(iodbc-usr-sdk.zip
), which updates the iODBC libraries that Apple ship with the operating system (/usr/lib/libiodbc*
). In addition, the SDK provides the C header files required to build ODBC applications along with the source code for iodbctest, the iODBC demonstration application. - The iODBC Driver Manager and Software Development Kit (
iodbc-sdk-version-macosx-osx-version.dmg
), which provides three iODBC frameworks: iODBC.framework (Driver Manager), iODBCinst.framework (Driver Manager configuration), iODBCadm.framework (GUI data source administrator, providing an alternative to ODBC Administrator).A framework is is a type of a bundle (directory) that contains shared resources such as dynamic shared libraries, header files, icons, and images. The system loads the code and resources of a framework into memory, as needed, and shares the one copy among all applications that need to access the framework.
If you want to run an ODBC application in 64-bit mode, the ODBC Driver Manager it is linked with must be 64-bit capable. In 64-bit mode, the ODBC Driver Manager can only load a 64-bit capable ODBC driver. Similarly, if you want to run an ODBC application in 32-bit mode, the ODBC Driver Manager it is linked with must be 32-bit capable. In 32-bit mode, the ODBC Driver Manager can only load a 32-bit capable ODBC driver.
On the Macintosh computer we used during testing for this article (macOS 10.7.2), the iODBC Driver Manager we installed from either of the SDKs mentioned earlier in this section supported both 32-bit and 64-bit architectures.
To find out which architectures your ODBC driver supports, use the file
command. In a Terminal window, run:
driver
where driver is the full path to the ODBC driver binary. On Intel 64 Macintosh computers, the file
command output will contain x86_64
if the ODBC driver binary contains a 64-bit driver. If the ODBC driver binary, contains a 32-bit driver, the file command output will contain i386
. For example, Easysoft's SQL Server ODBC driver, is a universal binary that contains both a 32-bit and a 64-bit driver:
cd /usr/local/easysoft/sqlserver/lib file libessqlsrv.so libessqlsrv.so is a Mach-O universal binary with 2 architectures i386 / x86_64
On PowerPC G5 Macintosh computers, the file command output will contain ppc64
if a 64-bit version of an ODBC driver is present in the ODBC driver binary and ppc7400
if a 32-bit version is present.
If your application and ODBC driver architectures are different, your connection will fail. For example, the following connection fails because the application can only run in 32-bit mode and the ODBC driver can only run in 64-bit mode:
$ cd /Library/Application\ Support/iODBC/bin $ file ./iodbctest ./iodbctest: Mach-O universal binary with 2 architectures ./iodbctest (for architecture ppc7400): Mach-O executable ppc ./iodbctest (for architecture i386): Mach-O executable i386 $ file /usr/local/lib/myodbcdriver.so /usr/local/lib/myodbcdriver.so: Mach-O 64-bit bundle x86_64 $ ./iodbctest "DSN=myodbcdriverdsn;UID=sa;PWD=p455w0rd" iODBC Demonstration program This program shows an interactive SQL processor Driver Manager: 03.52.0709.0909 1: SQLDriverConnect = [iODBC][Driver Manager]dlopen(/usr/local/lib/myodbcdriver.so, 6): no suitable image found. Did find: /usr/local/lib/myodbcdriver.so: mach-o, but wrong architecture (0) SQLSTATE=00000 2: SQLDriverConnect = [iODBC][Driver Manager]Specified driver could not be loaded (0) SQLSTATE=IM003
Frequently Asked Questions
- Do I need to use a 32-bit or 64-bit ODBC driver?
- How can I tell whether an application is 32-bit or 64-bit?
- Can I use a 32-bit ODBC driver on 64-bit platforms?
- My database is running on a 64-bit machine. Do I need to use a 64-bit ODBC driver to connect to it?
- How do I know whether my UNIX or Linux ODBC driver is the 64-bit or 32-bit
SQLLEN
orSQLULEN
version? - How do I obtain a 64-bit or 32-bit
SQLLEN
orSQLULEN
Easysoft ODBC driver for Linux and UNIX platforms? - How do I install both a 32-bit and a 64-bit SQL Server ODBC driver on Linux and UNIX?
- How do I install both a 32-bit and a 64-bit Easysoft ODBC driver on Windows?
- Why do I get error "testlib: not found" when installing a 32-bit Easysoft ODBC driver on my 64-bit Linux machine?
- Can I use a 64-bit Easysoft ODBC-ODBC Bridge client with a 32-bit Easysoft ODBC-ODBC Bridge server?
- Can I connect a 64-bit application to a 32-bit ODBC driver and vice versa?
- Which ODBC driver should I use with a 64-bit PHP package?
- I get a segmentation fault when retrieving a
NULL
SQL Server column with 64-bit PDO ODBC. What can I do?
Do I need to use a 32-bit or 64-bit ODBC driver?
Whether you use a 32-bit or 64-bit ODBC driver depends on whether your application is 32-bit or 64-bit. A 64-bit ODBC driver can only be used with a 64-bit application. Similarly, a 32-bit ODBC driver can only be used with a 32-bit application.
64-bit applications must be linked against 64-bit libraries (known as shared objects on UNIX and DLLs on Windows). For this reason, 64-bit applications can only link against a 64-bit ODBC Driver Manager shared object (or DLL). 64-bit ODBC Driver Managers can only load 64-ODBC drivers.
For the same reason, a 32-bit ODBC driver can only be used with a 32-bit application.
Note that it does not matter whether the database you are connecting to is 32-bit or 64-bit. Your choice of ODBC driver is dictated by the architecture of the client application not the database.
Examples
To connect | Use |
---|---|
A 64-bit version of IBM UniVerse or UniData to a SQL Server database. | A 64-bit SQL Server ODBC driver. |
A 32-bit version of Oracle HSODBC on a 64-bit platform to a SQL Server database. |
A 32-bit SQL Server ODBC driver.
32-bit ODBC drivers function perfectly well on 64-bit systems. |
A 32-bit version of Python to a 64-bit Oracle database. | A 32-bit Oracle ODBC driver. |
A 64-bit version of PHP to an Access database running on a 64-bit Windows machine. | A 64-bit ODBC-ODBC Bridge client and a 32-bit ODBC-ODBC Bridge server. |
How can I tell whether an application is 32-bit or 64-bit?
Because 32-bit and 64-bit applications can coexist on a 64-bit system, knowing whether your application platform architecture is 64-bit is not enough to determine whether an application is 64-bit or 32-bit. For example, IBM support Lotus Domino 7.x on 64-bit AIX, Solaris, Linux, and Windows machines, even though Domino 7.x is a 32-bit application.
Similarly, just because your application was included in a 64-bit distribution does not necessarily mean that it is also 64-bit. For example, the HSODBC component included in 64-bit Oracle distributions is 32-bit.
On UNIX systems, you can use the file
command to tell whether an application is 32-bit or 64-bit. To do this, locate the application binary and then run file file
. If the file is 64-bit, the command output will contain ELF 64-bit
(or something similar such as ELF-Class64
or ELF-64
). If the file is 32-bit, the command output will contain ELF 32-bit
.
(To check whether Lotus Domino is 64-bit, you can also type sh stat server
at the server console. The Server.Version.Architecture
statistic shows you whether Domino is 64-bit.)
In this example, the file
command's output shows that PHP's command line interface binary is 64-bit:
$ which php /usr/bin/php $ file /usr/bin/php /usr/bin/php: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped
This application, therefore, needs to be used with a 64-bit ODBC Driver Manager and ODBC driver, which can also be verified with the file
command. The unixODBC Driver Manager shared object is called libodbc.so
. You can find out the name of the ODBC driver shared object by checking the entry for the driver in /etc/odbcinst.ini
. Look at the Driver
attribute value.
For example:
$ locate libodbc.so /usr/local/easysoft/unixODBC/lib/libodbc.so /usr/local/easysoft/unixODBC/lib/libodbc.so.1 /usr/local/lib/libodbc.so /usr/local/lib/libodbc.so.1 $ file /usr/local/lib/libodbc.so /usr/local/lib/libodbc.so: symbolic link to `libodbc.so.1.0.0' $ file /usr/local/lib/libodbc.so.1.0.0 /usr/local/lib/libodbc.so.1.0.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), not stripped $ more /etc/odbcinst.ini | grep Driver Driver = /usr/local/easysoft/oracle/libesoracle.so Description = Easysoft ODBC-Oracle Driver $ file /usr/local/easysoft/oracle/libesoracle.so /usr/local/easysoft/oracle/libesoracle.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), not stripped
In the example, the output from the locate
command shows that there are two versions of unixODBC on this system. The version in /usr/local/easysoft
was included in the ODBC driver distribution. Because the ODBC driver is 64-bit (as proven by running file
), the Driver Manager supplied with it will always be 64-bit also.
Note Not all UNIX platforms use .so
as the shared object file extension. Some versions of HP-UX use .sl
. AIX uses archives (.a
) containing shared objects using the .o
extension.
In this next example, both components of a composite solution (PHP under Apache) are shown to be 64-bit:
$ which httpd /usr/sbin/httpd $ file /usr/sbin/httpd /usr/sbin/httpd: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, stripped $ locate libphp5.so /usr/lib64/httpd/modules/libphp5.so
Because the Apache HTTP Server binary is 64-bit, any Dynamic Shared Objects (DSOs) it needs to load must also be 64-bit. Because the DSO module for PHP is located under /usr/lib64
, there is no need to use file
to verify whether it is 64-bit. Only 64-bit libraries and object files are installed under directories called lib64
.
On Windows, run the application and open Task Manager (right-click the Taskbar, and then click Task Manager). If the application process has *32
after its name, it is a 32-bit application. Otherwise, it is a 64-bit application.
Can I use a 32-bit ODBC driver on 64-bit platforms?
Yes. On 64-bit platforms, 32-bit ODBC drivers are available to 32-bit applications, but not to 64-bit applications. What determines your choice of ODBC driver architecture is whether your application is 32-bit or 64-bit not whether your client platform (or database platform or DBMS) is 32-bit or 64-bit.
For example, HSODBC is 32-bit even though it may have been included in a 64-bit Oracle distribution and installed on a 64-bit machine. (HSODBC is an Oracle component which uses ODBC to enable Oracle client applications to transparently access non-Oracle databases.) You therefore must use HSODBC with a 32-bit ODBC driver.
There may be both a 32-bit and a 64-bit ODBC driver available for your platform, but you must use the 32-bit driver if your application is 32-bit.
My database is running on a 64-bit machine. Do I need to use a 64-bit ODBC driver to connect to it?
No. The database platform architecture does not affect whether you need to use a 64-bit or a 32-bit ODBC driver. 64-bit database editions are compatible with 32-bit applications and support client access through a 32-bit ODBC driver without requiring any changes to application code. If your application is 64-bit, you must use a 64-bit ODBC driver regardless of database platform architecture.
Similarly, you can access a 32-bit database edition with either a 64-bit application or ODBC driver or a 32-bit application or ODBC driver.
How do I know whether my UNIX or Linux ODBC driver is the 64-bit or 32-bit SQLLEN
or SQLULEN
version?
Easysoft ODBC drivers
Easysoft ODBC drivers that have been built with 64-bit SQLLEN
or SQLULEN
types contain ul64
in their distribution name. For example, odbc-oracle-3.2.17-linux-x86-64-ul64.tar
is the distribution name for a 64-bit SQLLEN
or SQLULEN
Oracle ODBC driver.
To find out the name of the distribution your Easysoft ODBC driver was installed from, look at the file /usr/local/easysoft/product_install.info
. For example, this .info
file for the Oracle ODBC driver shows that the driver was installed from odbc-oracle-3.2.17-linux-x86-64-ul64.tar
; the driver is therefore the 64-bit SQLLEN
and SQLULEN
version.
$ more /usr/local/easysoft/oracle_install.info product: odbc-oracle version: /tmp/odbc-oracle-3.2.17-linux-x86-64-ul64 date: Thu Dec 18 10:04:41 GMT 2008
If a 64-bit Easysoft ODBC driver distribution name does not include the -ul64
suffix, the driver it contains is the 32-bit SQLLEN
and SQLULEN
version. For example, odbc-sqlserver-1.1.4-linux-x86-64.tar
is the distribution name for a 32-bit SQLLEN
and SQLULEN
SQL Server ODBC driver.
The unixODBC Driver Manager included in the Easysoft ODBC driver distribution will always have been built with same size SQLLEN
and SQLULEN
types as the driver it is shipped with.
Non-Easysoft ODBC drivers
If you can install your ODBC driver under the unixODBC Driver Manager, you can use slencheck
, a unixODBC utility which attempts to check whether an ODBC driver was built with 32-bit or 64-bit SQLLEN
types.
slencheck
is included in unixODBC 2.3.2 and later. Note that you do not have to replace your existing unixODBC installation with unixODBC 2.3.2+ to use slencheck
.
These instructions show you how to use slencheck
. The instructions assume that you have installed your ODBC driver under a version of unixODBC that came with your driver or operating system distribution and that you have configured an ODBC data source for your driver.
-
Download, build, and install unixODBC 2.3.2. For example:
$ mkdir /home/myuser/unixODBC $ cd /tmp $ gunzip unixODBC-2.3.2-pre.tar.gz $ tar -xvf unixODBC-2.3.2-pre.tar $ cd unixODBC-2.3.2-pre $ ./configure --prefix=/home/myuser/unixODBC $ make $ make install
Replace
/home/myuser/unixODBC
with the directory where you want to install unixODBC. - Run
slencheck
against the ODBC data source for your driver.The
slencheck
command line format is:slencheck
dsn
[uid
[pwd
]]where:
dsn
is your ODBC data source.uid
is the user name required to access the target database server, if required and not stored in the data source.password
is the password foruid
, if required and not stored in the data source.
For example:
$ cd /home/myuser/unixODBC/bin $ ODBCSYSINI=/etc ./slencheck MYDSN slencheck: sizeof(
SQLLEN
) == 8 slencheck: Driver Manager and driver matchedIf
slencheck
reports theSQLLEN
size as 4, the ODBC driver has been built with 32-bitSQLLEN
types. Ifslencheck
reports theSQLLEN
size as 8, the ODBC driver has been built with 64-bitSQLLEN
types.Note
slencheck
probes the unixODBC Driver Manager to determine whether it has been built with the same sizeSQLLEN
types as the ODBC driver. By default,slencheck
probes the Driver Manager in the distribution it is included with, not the Driver Manager your ODBC driver is installed under. For example, in the command shown earlier,slencheck
probes the Driver Manager in/home/myuser/unixODBC/lib
.
How do I obtain a 64-bit or 32-bit SQLLEN
or SQLULEN
Easysoft ODBC driver for Linux and UNIX platforms?
Product | Version | How to get |
---|---|---|
Oracle ODBC driver | 64-bit SQLLEN and SQLULEN |
Download the 64-bit ODBC driver from Easysoft web site. |
Oracle ODBC driver | 32-bit SQLLEN and SQLULEN |
Email the Easysoft Support team (). |
SQL Server ODBC driver | 64-bit SQLLEN and SQLULEN |
Download the 64-bit ODBC driver from Easysoft web site. |
SQL Server ODBC driver | 32-bit SQLLEN and SQLULEN |
Email the Easysoft Support team (). |
Salesforce ODBC driver | 64-bit SQLLEN and SQLULEN |
Download the 64-bit ODBC driver from Easysoft web site. |
Salesforce ODBC driver | 32-bit SQLLEN and SQLULEN |
Email the Easysoft Support team (). |
MongoDB ODBC driver | 64-bit SQLLEN and SQLULEN |
Download the 64-bit ODBC driver from Easysoft web site. |
MongoDB ODBC driver | 32-bit SQLLEN and SQLULEN |
Email the Easysoft Support team (). |
DB2 ODBC driver | 64-bit SQLLEN and SQLULEN |
Download the 64-bit ODBC driver from Easysoft web site. |
DB2 ODBC driver | 32-bit SQLLEN and SQLULEN |
Email the Easysoft Support team (). |
Derby ODBC driver | 64-bit SQLLEN and SQLULEN |
Download the 64-bit ODBC driver from Easysoft web site. |
Derby ODBC driver | 32-bit SQLLEN and SQLULEN |
Email the Easysoft Support team (). |
Other Easysoft ODBC driver | 64-bit SQLLEN and SQLULEN |
Email the Easysoft Sales team (). |
Other Easysoft ODBC driver | 32-bit SQLLEN and SQLULEN |
Download the 64-bit ODBC driver from Easysoft web site. |
How do I install both a 32-bit and a 64-bit SQL Server ODBC driver on Linux and UNIX?
- Install and license the 32-bit SQL Server ODBC driver.
For installation instructions, see the ODBC driver documentation. Refer to the documentation to see which environment variables you need to set (
LD_LIBRARY_PATH
,LIBPATH
,LD_RUN_PATH
,SHLIB_PATH
depending on the platform and linker). - Create an ODBC data source in
/etc/odbc.ini
that connects to the target database. - To verify the 32-bit ODBC driver installation, use isql to connect to the new data source. For example:
$ cd /usr/local/easysoft/unixODBC/bin $ ./isql.sh -v MSSQL-DSN
At the prompt, enter
help
to display a list of tables. To exit, press return in an empty prompt line. - Install the 64-bit SQL Server ODBC driver:
- When the installer asks you to "Enter a base install directory", enter:
/usr/local/easysoft64
- Make sure that you do not use the unixODBC Driver Manager the installer finds in
/usr/local/easysoft/unixODBC
. - Do not replace the sample data source.
- Do not request a new license unless you are installing a
Linux x86_64
ODBC driver distribution.
- When the installer asks you to "Enter a base install directory", enter:
- Create the following links between the 32-bit and 64-bit installations:
# cd /usr/local/easysoft # ln -s /usr/local/easysoft64/easysoft/lib lib64 # ln -s /usr/local/easysoft64/easysoft/etc etc64 # ln -s /usr/local/easysoft64/easysoft/sqlserver sqlserver64 # cd unixODBC # ln -s /usr/local/easysoft64/easysoft/unixODBC/bin bin64 # ln -s /usr/local/easysoft64/easysoft/unixODBC/lib lib64
- Add entries for both the 32-bit and 64-bit ODBC driver to
/etc/odbcinst.ini
.In the
/etc/odbcinst.ini
section for the ODBC driver, specify the 32-bit ODBC driver shared object with theDriver
attribute; add aDriver64
attribute that specifies the 64-bit ODBC driver shared object.For example, this
/etc/odbcinst.ini
section specifies just the shared object for the 64-bit SQL Server ODBC driver:[Easysoft ODBC-SQL Server] Driver=/usr/local/easysoft64/easysoft/sqlserver/lib/libessqlsrv.so Setup=/usr/local/easysoft64/easysoft/sqlserver/lib/libessqlsrvS.so Threading=0 FileUsage=1 DontDLClose=1 UsageCount=2
The section has now been changed to specify both the 32-bit and 64-bit ODBC driver shared objects:
[Easysoft ODBC-SQL Server] Driver=/usr/local/easysoft/sqlserver/lib/libessqlsrv.so Driver64=/usr/local/easysoft/sqlserver64/lib/libessqlsrv.so Setup=/usr/local/easysoft64/easysoft/sqlserver/lib/libessqlsrvS.so Threading=0 FileUsage=1 DontDLClose=1 UsageCount=2
- Edit the startup file for isql to specify the correct library paths. (Note You will need to make the same changes to the library search path for your application.)
- Open
/usr/local/easysoft/unixODBC/bin64/isql.sh
in a text editor. - Change these lines:
if [ -r /usr/local/easysoft/etc/es.ld.so.conf ];then ldpaths=`cat /usr/local/easysoft/etc/es.ld.so.conf
To:
if [ -r /usr/local/easysoft/etc64/es.ld.so.conf ];then ldpaths=`cat /usr/local/easysoft/etc64/es.ld.so.conf
- Change this line:
/usr/local/easysoft/unixODBC/bin/isql $*
To:
/usr/local/easysoft/unixODBC/bin64/isql $*
- Open
- If you are using Linux x86/x86_64 ODBC driver distributions, you need a license for both the 32-bit and 64-bit ODBC drivers. The two licences can be obtained during the installation and the license entry from the two license files can be combined into the one file:
# cat /usr/local/easysoft64/easysoft/license/licenses >> /usr/local/easysoft/license/licenses
- Test the 64-bit SQL Server ODBC driver installation:
$ /usr/local/easysoft/unixODBC/bin64/isql.sh -v MSSQL-DSN
- Test the existing 32-bit SQL Server ODBC driver installation:
$ /usr/local/easysoft/unixODBC/bin/isql.sh -v MSSQL-DSN
How do I install both a 32-bit and a 64-bit Easysoft ODBC driver on Windows?
On 64-bit Windows platforms, the Easysoft ODBC driver installation program installs both a 32-bit and a 64-bit version of the ODBC driver. On 64-bit Windows platforms therefore, Easysoft ODBC drivers are automatically available to both 32-bit and 64-bit applications.
Why do I get error "testlib: not found" not found when installing a 32-bit Easysoft ODBC driver on my 64-bit Linux machine?
Easysoft ODBC driver distributions contain a small C program named testlib
, which is run during installation to make sure that the prerequisite C runtime libraries are present. If the 32-bit C runtime libraries are not installed on your 64-bit machine, which is the case in some of the more recent 64-bit Linux distributions, testlib
will not be accessible to your (64-bit) C runtime and the Easysoft installation will abort with an error similar to:
Testing this machine for libc5/glibc compatability. ./install_check_linux: 121: ./testlib: not found
The solution is to install the 32-bit C runtime libraries, which in some Linux distributions are contained in the libc6-i386 package.
testlib
is described in more detail in this Easysoft Knowledge Base article.
Can I use a 64-bit Easysoft ODBC-ODBC Bridge client with a 32-bit Easysoft ODBC-ODBC Bridge server?
Yes. You can use a 64-bit ODBC-ODBC Bridge client with a 32-bit ODBC-ODBC Bridge server and a 32-bit ODBC-ODBC Bridge client with a 64-bit ODBC-ODBC Bridge server.
The application and the ODBC driver you need the ODBC-ODBC Bridge to provide the connectivity between dictate whether you need to use a 32-bit or 64-bit ODBC-ODBC Bridge component.
If the application that you want to use the ODBC-ODBC Bridge client with is 32-bit, you must use a 32-bit ODBC-ODBC Bridge client. If the application that you want to use the ODBC-ODBC Bridge client with is 64-bit, you must use a 64-bit ODBC-ODBC Bridge client.
If the ODBC driver that you want to use the ODBC-ODBC Bridge server with is 32-bit, you must use a 32-bit ODBC-ODBC Bridge server. If the ODBC driver that you want to use the ODBC-ODBC Bridge server with is 64-bit, you must use a 64-bit ODBC-ODBC Bridge server.
A 32-bit ODBC-ODBC Bridge client can connect to a 64-bit ODBC-ODBC Bridge server and vice versa. For example, using a 64-bit ODBC-ODBC Bridge client with a 32-bit ODBC-ODBC Bridge server enables a 64-bit application to connect to a data source for a 32-bit ODBC driver.
To illustrate this, we used the ODBC-ODBC Bridge for Windows to connect a 64-bit Strawberry Perl distribution to a data source for the 32-bit Microsoft Access ODBC driver:
- On our 64-bit Windows machine, we ran the following command to verify that we were using a 64-bit Strawberry Perl distribution:
perl -V
In the command output
archname=MSWin32-x64-multi-thread
, confirms that the Perl distribution is 64-bit. - We configured and tested a Microsoft Access ODBC driver data source and attempted to connect to the data source with the following Perl script:
#!/usr/bin/perl -w use strict; use DBI; my $dbh = DBI-> connect('dbi:ODBC:Northwind'); $dbh->disconnect if ($dbh);
- As expected, attempting to use a 64-bit application with a 32-bit ODBC driver failed, and we got the following error when running the script:
[Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application
- We then installed the 64-bit Windows ODBC-ODBC Bridge distribution.
We accepted the default option during Setup, which installed both the ODBC-ODBC Bridge client and server components.
- Using the 64-bit ODBC Data Source Administrator, we configured an ODBC-ODBC Bridge client data source that pointed to our Access ODBC driver data source.
- We changed the Perl script to specify the ODBC-ODBC Bridge client data source.
my $dbh = DBI-> connect('dbi:ODBC:ODBC-ODBC Bridge_Northwind');
The script then ran successfully.
Can I connect a 64-bit application to a 32-bit ODBC driver and vice versa?
Yes, you can use the ODBC-ODBC Bridge to connect a 64-bit application to a 32-bit ODBC driver and a 32-bit application to a 64-bit ODBC driver. For more information, refer to:
- Can I can connect a 64-bit application to a 32-bit ODBC driver?
- Can I can connect a 32-bit application to a 64-bit ODBC driver?
Which ODBC driver should I use with a 64-bit PHP package?
If you want to connect to an ODBC data source from a version of PHP that has been packaged for your Linux distribution, you need to install the corresponding PHP ODBC package. For example, php5-odbc. PHP ODBC contains two ODBC "applications," Unified ODBC and PDO ODBC, which provide two ways of connecting to an ODBC data source from PHP. PHP ODBC also contains the unixODBC Driver Manager, which both the Unified ODBC and PDO ODBC libraries are linked against.
To find out which ODBC driver you should use with PHP ODBC, first locate and check the architecture of the Unified ODBC and PDO ODBC libraries (odbc.so
and pdo_odbc.so
). For example:
$ cd /usr/lib/php5/20121212/ $ file odbc.so pdo_odbc.so odbc.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=c0ff22b1f55cae973783fe5c54c92cd13a0f428f, stripped pdo_odbc.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=84cec3bbecb33d7af4b1c63c581ef4908515d8e8, stripped
The file
command's output confirms that this is a 64-bit PHP ODBC package, which should be used with a 64-bit ODBC Driver Manger and a 64-bit ODBC driver. The unixODBC Driver Manager included in the package therefore has also to be 64-bit:
$ ldd odbc.so pdo_odbc.so odbc.so: libodbc.so.1 => /usr/lib/x86_64-linux-gnu/libodbc.so.1 (0x00007f526229f000) pdo_odbc.so: libodbc.so.1 => /usr/lib/x86_64-linux-gnu/libodbc.so.1 (0x00007fce8681f000) $ file /usr/lib/x86_64-linux-gnu/libodbc.so.1 /usr/lib/x86_64-linux-gnu/libodbc.so.1: symbolic link to `libodbc.so.1.0.0' $ file /usr/lib/x86_64-linux-gnu/libodbc.so.1.0.0 /usr/lib/x86_64-linux-gnu/libodbc.so.1.0.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=618af8b657a8991653f52ff47769439e1c41b955, stripped
Determining whether you need to use a 64-bit or 32-bit SQLLEN
ODBC driver with PHP is harder to establish. Researching on the web / examining Valgrind and Driver Manager logs / trying PHP with 32-bit and 64-bit SQLLEN
ODBC drivers indicates that:
- Unified ODBC has been built with 64-bit size
SQLLEN
types. - PDO ODBC has been built with 32-bit size
SQLLEN
types.
We used these sample scripts to identify which version of our SQL Server ODBC driver to use with PHP.
<?php // PDO ODBCSQLLEN
example. // This script will generate a "memory allocation" error if run with a 64-bitSQLLEN
ODBC driver. // Prerequisite table is: // CREATE TABLE MyTable (MyNvarcharCol nvarchar(200)) // INSERT INTO MyTable values ('test') $pdo = new PDO('odbc:my_odbc_dsn', 'my_user', 'my_password'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); $sth = $pdo->prepare("SELECT COUNT(*) FROM MyTable WHERE MyNvarcharCol = :my_value"); $sth->execute(array('my_value' => 'test')); ?>
<?php // Unified ODBCSQLLEN
example. // This script will generate a segmentation fault if run with a 32-bitSQLLEN
ODBC driver. // WARNING: This script may crash PHP, affecting other PHP users on the machine. // Prerequisite table is: // CREATE TABLE MyTable (MyCol1 char(20), MyCol2 char(20)) // INSERT INTO MyTable (MyCol1) values ('test') $con = odbc_connect("my_odbc_dsn", "my_user", "my_password"); $rs2 = odbc_exec($con, "select * from MyTable"); if (odbc_fetch_row($rs2)) { $field = odbc_result($rs2,"MyCol2"); } odbc_close($con); ?>
Note The PHP ODBC package contains one copy of the unixODBC Driver Manager. This Driver Manager will have been built with different size SQLLEN
types to either PDO ODBC or Unified ODBC (we do not know which). To ensure that your ODBC application (PDO ODBC or Unified OBDC, in this case), ODBC Driver Manager and ODBC driver have all been built with the same size SQLLEN
types, use the ODBC application with the version of the Driver Manager that is included in your ODBC driver distribution. For example:
LD_LIBRARY_PATH=/usr/local/easysoft/unixODBC/lib:$LD_LIBRARY_PATH php 64-bit-pdo.php
I get a segmentation fault when retrieving a NULL
SQL Server column with 64-bit PDO ODBC. What can I do?
Rebuild PDO ODBC from source obtained from the PHP GitHub site against unixODBC 2.3.0+. In the following example, PDO ODBC is built against the 2.3.0 Driver Manager included with Easysoft's SQL Server ODBC driver. Doing this not only fixes the issue with NULL
s, but also ensures that the application (PDO ODBC, in this case), Driver Manager and ODBC driver are all built with the same size SQLLEN
types (namely, 64-bit):
$ git clone https://github.com/php/php-src.git php-src $ cd php-src $ ./configure --with-unixODBC=shared,/usr/local/easysoft/unixODBC \ --with-pdo-odbc=shared,unixODBC,/usr/local/easysoft/unixODBC $ make $ make install $ cd /etc $ if ! grep odbc.so php.ini; then echo "extension=odbc.so" >> php.ini; fi $ if ! grep pdo_odbc.so php.ini; then echo "extension=pdo_odbc.so" >> php.ini; fi
Note
- Although the only files need to resolve the issue are
odbc.so
andpdo_odbc.so
it is not possible to simply replace these files in your existing PHP distribution with the new files. This is because there is a mechanism in PHP that prevents extensions from being used with a different version of PHP to the one that they were built with. There is a workaround for this however.