dbserverenum

Searches for the names of SQL Servers locally, over the network, or both.

Syntax

INT dbserverenum (
USHORT
searchmode,
LPSTR
servnamebuf,
USHORT
sizeservnamebuf,
LPUSHORT
numentries );

where

searchmode
Defines whether the dbserverenum function checks for server names locally, on the network, or both.

Set searchmode to loc_search to search for the names of servers in the WIN.INI file (Windows) or in the following subtree of the Windows NT Registry:

HKEY_LOCAL_MACHINE\
SOFTWARE\
Microsoft\
MSSQLServer\
Client\
ConnectTo

The loc_search constant has the value 0x0001.

To search for the names of servers registered by the default Net-Library, set searchmode to net_search. The net_search constant has the value 0x0002.

To search both locally and on the network for server names, use a bitwise OR operation (net_search | loc_search) to combine the values of loc_search and net_search. In this case, a server name is duplicated if the server name is defined both locally and on the network.

DB-Library first tries to load the default Net-Library set by the DSQUERY entry in the Windows NT Registry or in the .INI file (Windows). If no default entry exists, DB-Library loads the appropriate named pipe Net-Library.

servnamebuf
Is a pointer to a buffer that stores the server names returned by a search. When the dbserverenum function successfully returns a list of server names, the servnamebuf buffer contains the server names separated by null characters. The end of the list is designated by two consecutive null characters. Only complete server names are copied to the buffer. When a buffer is full and there are additional names that could not be copied to the buffer, dbserverenum returns the value more_data. Server names are returned in non-sorted order; names found using the loc_search constant are returned before those names found using the net_search constant. Note that dbserverenum can return server names even when the SQL Server is not running. Therefore, although a server name is returned in the list of servers, it does not guarantee that you can access the server.
sizeservnamebuf
Specifies the size of the buffer for the server names returned by a successful search. The buffer size limits the maximum number of names that dbserverenum can return in a single call.
numentries
Returns the number of server names copied to the buffer by the current call to dbserverenum.

Returns

The dbserverenum function returns one or more of the following status code constants:

enum_success (0x0000)
Indicates that the search to detect server names succeeded. enum_success can be returned even when no servers are detected (when numentries = 0).
more_data (0x0001)
Indicates that DB-Library has enough memory to service the dbserverenum request but the buffer passed to dbserverenum is not large enough to hold all the names returned. Increasing the size of sizeservnamebuf enables the buffer to hold more server names.
net_not_available (0x0002)
Indicates that the Net-Library DLL is unavailable. A Net-Library DLL might be unavailable because no DLL is found or because the available Net-Library DLL does not support the dbserverenum function. When the searchmode parameter includes the net_search mode, dbserverenum calls the default Net-Library DLL. When searchmode includes both the net_search and loc_search modes (net_search | loc_search), dbserverenum can return both more_data and net_not_available (more_data | net_not_available).
out_of_memory (0x0004)
Indicates that DB-Library cannot allocate enough memory to service the dbserverenum request.
not_supported (0x0008)
Indicates that the capability is not supported by the current Net-Library version or the current server platform.
enum_invalid_param (0x0010)
Indicates that an invalid parameter, such as a null pointer, was passed to the function.

Remarks

Using dbserverenum, you can obtain the names of servers to which you can connect. The dbserverenum function can search for the names of SQL Servers either locally or over the network. For network searches, the Net-Library DLL used must support the dbserverenum function. A Net-Library DLL registers and finds servers on networks for a specific network environment such as LAN Manager - based networks.

When the search mode is set to net_search, dbserverenum calls the default Net-Library DLL (for example, named pipes or NovellŪ IPX/SPX). Because only one Net-Library DLL can be the default, those servers discernible to the specific Net-Library are enumerated using the net_search parameter. You must add a specific server entry in the Windows NT Registry to use a Net-Library DLL other than the default Net-Library DLL. Servers listed in the Registry are enumerated when the search mode is set to loc_search.

See Also

dbopen