| title | LocalDBGetInstances Function |
|---|---|
| description | LocalDBGetInstances returns all SQL Server Express LocalDB instances with the given version. |
| author | markingmyname |
| ms.author | maghan |
| ms.reviewer | randolphwest |
| ms.date | 07/14/2025 |
| ms.service | sql |
| ms.topic | reference |
| apilocation | sqluserinstance.dll |
| apiname | LocalDBGetInstances |
| apitype | DLLExport |
[!INCLUDE SQL Server]
Returns all SQL Server Express LocalDB instances with the given version.
Header file: msoledbsql.h
#define MAX_LOCALDB_INSTANCE_NAME_LENGTH 128typedef WCHAR TLocalDBInstanceName [ MAX_LOCALDB_INSTANCE_NAME_LENGTH + 1 ] ;
typedef TLocalDBInstanceName* PTLocalDBInstanceName;
HRESULT LocalDBGetInstances(
PTLocalDBInstanceName pInstanceNames ,
LPDWORD lpdwNumberOfInstances
);[Output] When this function returns, contains the names of both named and default LocalDB instances on the user's workstation.
[Input/Output] On input, this option contains the number of slots for instance names in the pInstanceNames buffer. On output, this option contains the number of LocalDB instances found on the user's workstation.
S_OK: The function succeeded.
| Error | Description |
|---|---|
| LOCALDB_ERROR_NOT_INSTALLED | SQL Server Express LocalDB isn't installed on the computer. |
| LOCALDB_ERROR_INVALID_PARAMETER | One or more specified input parameters are invalid. |
| LOCALDB_ERROR_INSUFFICIENT_BUFFER | The input buffer is too short, and truncation wasn't requested. |
| LOCALDB_ERROR_INSTANCE_FOLDER_PATH_TOO_LONG | The path where the instance should be stored is longer than MAX_PATH. |
| LOCALDB_ERROR_CANNOT_ACCESS_INSTANCE_REGISTRY | An instance registry can't be accessed. |
| LOCALDB_ERROR_INSTANCE_CONFIGURATION_CORRUPT | An instance configuration is corrupted. |
| LOCALDB_ERROR_INTERNAL_ERROR | An unexpected error occurred. See the event log for details. |
For a code sample that uses LocalDB API, see SQL Server Express LocalDB reference.