Delen via


LocalDBGetInstanceInfo function

Applies to:SQL Server

Retourneert informatie voor het opgegeven SQL Server Express LocalDB-exemplaar, zoals of deze bestaat, de LocalDB-versie die wordt gebruikt, of deze wordt uitgevoerd, enzovoort.

De informatie wordt geretourneerd in een struct benoemde, LocalDBInstanceInfodie de volgende definitie heeft.

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

[Invoer] De naam van het exemplaar.

pInstanceInfo

[Uitvoer] De buffer voor het opslaan van de informatie over het LocalDB-exemplaar.

dwInstanceInfoSize

[Input] Holds the size of the InstanceInfo buffer.

Returns

S_OK: De functie is geslaagd.

Error Description
LOCALDB_ERROR_NOT_INSTALLED SQL Server Express LocalDB is niet geïnstalleerd op de computer.
LOCALDB_ERROR_INVALID_PARAMETER Een of meer opgegeven invoerparameters zijn ongeldig.
LOCALDB_ERROR_INVALID_INSTANCE_NAME De opgegeven exemplaarnaam is ongeldig.
LOCALDB_ERROR_UNKNOWN_INSTANCE Het exemplaar bestaat niet.
LOCALDB_ERROR_INSTANCE_FOLDER_PATH_TOO_LONG Het pad waar het exemplaar moet worden opgeslagen, is langer dan MAX_PATH.
LOCALDB_ERROR_CANNOT_ACCESS_INSTANCE_FOLDER Er kan geen exemplaarmap worden geopend.
LOCALDB_ERROR_CANNOT_ACCESS_INSTANCE_REGISTRY Er kan geen exemplaarregister worden geopend.
LOCALDB_ERROR_INSTANCE_CONFIGURATION_CORRUPT Een exemplaarconfiguratie is beschadigd.
LOCALDB_ERROR_INTERNAL_ERROR Er is een onverwachte fout opgetreden. Zie het gebeurtenislogboek voor meer informatie.

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. Anders wordt LOCALDB_ERROR_INVALID_PARAMETER geretourneerd.

Een typisch voorbeeld van LocalDBGetInstanceInfo API-gebruik ziet er als volgt uit:

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

Zie sql Server Express LocalDB-referentie voor een codevoorbeeld dat gebruikmaakt van de LocalDB-API van LocalDB.