Win32 DB-Library Architecture

Internally, a separate operating system thread is spawned for each connection that DB-Library makes with SQL Server. Each instance of the DB-Library DLL that is loaded by a calling process gets a private data area, while sharing code.

The Win32 DB-Library architecture differs from the implementation with Windows 3.x. In Windows 3.x, the DB-Library DLL has a single data segment that is shared among all calling processes. W3DBLIB.DLL maintains DB-Library connections as a linked list of connections in a single data segment. This architecture is required, because in Windows 3.x DLLs have a single data segment that is shared among all calling processes. This necessitates the initialization and clean up of the DB-Library DLL data structures through calls to the dbinit and dbwinexit functions.

The DB-Library functions for Win32 are located in NTWDBLIB.DLL, and the named pipe Net-Library is located in DBNMPNTW.DLL. (Be sure to set the PATH environment variable to include the directory where the DLLs reside.)

Another file, NTWDBLIB.LIB, contains import definitions that your applications for the Win32 API use. Set the LIB environment variable to include the directory where NTWDBLIB.LIB resides.

DB-Library resolves server names differently depending on the client platform.

Resolving Server Names for Clients Based on Windows, MS-DOS, OS/2, and Windows NT

When dbopen (the DB-Library function that initiates a client conversation with SQL Server) is called with the name of a SQL Server to connect to, DB-Library uses configuration information to determine which client-side Net-Library to load.

The client-side Net-Library configuration is stored in the following locations:

Client

Net-Library configuration is stored in

Windows 3.x

WIN.INI

MS-DOS

Environment variable

OS/2

OS2.INI

Windows NT

Windows NT Registry


DB-Library scans the [SQLSERVER] section of WIN.INI, OS2.INI, or the \SQLServer\Client\ConnectTo subtree of the Windows NT Registry looking for a logical name that matches the servername parameter specified in the call to dbopen. All items in the [SQLSERVER] section of the .INI file or in the Registry subtree have this format:


logical-name=Net-Lib-DLL-name[,network-specific-parameters]

Note Although some Net-Libraries need values for network-specific-parameters, this is optional for others that instead use defaults or determine the network-specific information required themselves.

DB-Library uses the following logic to determine which Net-Library to load:

The following examples illustrate this logic:

The Windows named pipe Net-Library is used, and it connects to SQL Server \\Forecast using the standard named pipe, \pipe\sql\query.

The Windows named pipe Net-Library is used, and it connects to \\server1, where SQL Server has been started using an alternate named pipe, \pipe\sql2\query.

Note

SQL Server can be directed to use an alternate pipe by adding an entry to the ListenOn field in the Registry under the following tree:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SQLServer\Server

The SPX Net-Library is used, and the servername parameter from dbopen is used. This Net-Library requires no specific network connection information because it queries the NetWare Bindery to determine the location of the server running the Network Manager service specified in the servername parameter.

The SYBASE TCP/IP Net-Library is used, and DB-Library passes the IP address and port number contained in the initialization string to the Net-Library.

Note

The SQL Server ODBC driver uses the same Net-Libraries as DB-Library to communicate with SQL Server, Open Data Services, and SQL Bridge.

Resolving Server Names for MS-DOS–Based Clients

With MS-DOS, only one Net-Library TSR can be loaded, so there is no .INI configuration. Instead, MS-DOS environment variables are used to specify any network-specific connection information. Environment variables have the following format:


logical-name=network-specific-parameters

The Net-Library used is the currently loaded TSR. If the servername parameter passed to dbopen corresponds to a currently set environment variable, DB-Library passes the information contained in the environment string to the currently loaded Net-Library. In turn, Net-Library uses this information to determine server location and network-specific information parameters, if present. If no environment variable matches the servername passed to dbopen, DB-Library passes the servername parameter from dbopen to the currently loaded Net-Library.

New DB-Library Function Identifies SQL Servers

DB-Library version 4.20.20 and later includes a new function (dbserverenum) that enables applications to identify SQL Servers available on the network, regardless of which network operating system is being used. For details on the dbserverenum function, see the Microsoft SQL Server Programmer's Reference for C.