Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

LocalDBGetInstanceInfo Function

Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to existing features in Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2).

Returns information for the specified SQL Server Express LocalDB instance, such as whether it exists, the LocalDB version it uses, whether it is running, and so on.

The information is returned in a struct named LocalDBInstanceInfo, which has the following definition.

typedef struct _LocalDBInstanceInfo
      // Contains the size of the LocalDBInstanceInfo struct
      DWORD  cbLocalDBInstanceInfoSize;

      // Holds the instance name

      // TRUE if the instance files exist on disk, FALSE otherwise
      BOOL   bExists;

      // TRUE if the instance configuration registry is corrupted, FALSE otherwise

      // TRUE if the instance is running at the moment, FALSE otherwise
      BOOL   bIsRunning;

      // Holds the LocalDB version for the instance in the format: major.minor.build.revision
      DWORD  dwMajor;
      DWORD  dwMinor;
      DWORD  dwBuild;
      DWORD  dwRevision;

      // Holds the date and time when the instance was started for the last time
      FILETIME ftLastStartUTC;

      // Holds the name of the TDS named pipe to connect to the instance

      // TRUE if the instance is shared, FALSE otherwise

      // Holds the shared name for the instance (if the instance is shared)

      // Holds the SID of the instance owner (if the instance is shared)

      // TRUE if the instance is Automatic, FALSE otherwise
} LocalDBInstanceInfo;

Header file: sqlncli.h

HRESULT LocalDBGetInstanceInfo(
           PCWSTR wszInstanceName,
           PLocalDBInstanceInfo pInstanceInfo,
           DWORD dwInstanceInfoSize 


[Input] The instance name.


[Output] The buffer to store the information about the LocalDB instance.


[Input] Holds the size of the InstanceInfo buffer.


The function succeeded.


SQL Server Express LocalDB is not installed on the computer.


One or more specified input parameters are invalid.


The specified instance name is invalid.


The instance does not exist.


The path where the instance should be stored is longer than MAX_PATH.


An instance folder cannot be accessed.


An instance registry cannot be accessed.


An instance configuration is corrupted.


An unexpected error occurred. See the event log for details.

The rationale behind the introduction of the struct size argument (lpInstanceInfoSize) is to enable the API to return different versions of the LocalDBInstanceInfo struct, effectively enabling forward and backward compatibility.

If the struct size argument (lpInstanceInfoSize) matches the size of a known version of the LocalDBInstanceInfo struct, that version of the struct is returned. Otherwise, LOCALDB_ERROR_INVALID_PARAMETER is returned.

A typical example of LocalDBGetInstanceInfo API usage looks like this:

LocalDBInstanceInfo ii;
LocalDBInstanceInfo(L”Test”, &ii, sizeof(LocalDBInstanceInfo));

For a code sample that uses LocalDB API, see SQL Server Express LocalDB Reference.

Community Additions

© 2015 Microsoft