Dela via


LocalDBGetInstanceInfo function

Applies to:SQL Server

Returnerar information för den angivna SQL Server Express LocalDB-instansen, till exempel om den finns, den LocalDB-version som används, om den körs och så vidare.

Informationen returneras i en struct namngiven LocalDBInstanceInfo, som har följande definition.

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

      // Holds the instance name
      TLocalDBInstanceNamewszInstanceName;

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

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

      // 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
      WCHARwszConnection;

      // TRUE if the instance is shared, FALSE otherwise
      BOOLbIsShared;

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

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

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

Header file:msoledbsql.h

Syntax

HRESULT LocalDBGetInstanceInfo(
           PCWSTR wszInstanceName ,
           PLocalDBInstanceInfo pInstanceInfo ,
           DWORD dwInstanceInfoSize
);

Arguments

wszInstanceName

[Indata] Instansnamnet.

pInstanceInfo

[Utdata] Bufferten för att lagra information om LocalDB-instansen.

dwInstanceInfoSize

[Input] Holds the size of the InstanceInfo buffer.

Returns

S_OK: Funktionen lyckades.

Error Description
LOCALDB_ERROR_NOT_INSTALLED SQL Server Express LocalDB är inte installerat på datorn.
LOCALDB_ERROR_INVALID_PARAMETER En eller flera angivna indataparametrar är ogiltiga.
LOCALDB_ERROR_INVALID_INSTANCE_NAME Det angivna instansnamnet är ogiltigt.
LOCALDB_ERROR_UNKNOWN_INSTANCE Instansen finns inte.
LOCALDB_ERROR_INSTANCE_FOLDER_PATH_TOO_LONG Sökvägen där instansen ska lagras är längre än MAX_PATH.
LOCALDB_ERROR_CANNOT_ACCESS_INSTANCE_FOLDER Det går inte att komma åt en instansmapp.
LOCALDB_ERROR_CANNOT_ACCESS_INSTANCE_REGISTRY Det går inte att komma åt ett instansregister.
LOCALDB_ERROR_INSTANCE_CONFIGURATION_CORRUPT En instanskonfiguration är skadad.
LOCALDB_ERROR_INTERNAL_ERROR Ett oväntat fel uppstod. Mer information finns i händelseloggen.

Details

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

If the struct size argument (lpInstanceInfoSize) matches the size of a known version of the LocalDBInstanceInfostruct, that version of the struct is returned. Annars returneras LOCALDB_ERROR_INVALID_PARAMETER.

Ett typiskt exempel på LocalDBGetInstanceInfo API-användning ser ut så här:

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

Ett kodexempel som använder LocalDB API finns i SQL Server Express LocalDB-referens.