Partager via


LocalDBGetInstanceInfo function

Applies to:SQL Server

Retourne des informations pour l’instance SQL Server Express LocalDB spécifiée, par exemple s’il existe, la version localDB qu’elle utilise, si elle est en cours d’exécution, etc.

Les informations sont retournées dans un struct nom LocalDBInstanceInfo, qui a la définition suivante.

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

[Entrée] Nom de l'instance.

pInstanceInfo

[Sortie] La mémoire tampon pour stocker des informations sur l'instance de LocalDB.

dwInstanceInfoSize

[Input] Holds the size of the InstanceInfo buffer.

Returns

S_OK: la fonction a réussi.

Error Description
LOCALDB_ERROR_NOT_INSTALLED SQL Server Express LocalDB n’est pas installé sur l’ordinateur.
LOCALDB_ERROR_INVALID_PARAMETER Un ou plusieurs paramètres d'entrée spécifiés ne sont pas valides.
LOCALDB_ERROR_INVALID_INSTANCE_NAME Le nom d'instance spécifié n'est pas valide.
LOCALDB_ERROR_UNKNOWN_INSTANCE L’instance n’existe pas.
LOCALDB_ERROR_INSTANCE_FOLDER_PATH_TOO_LONG Chemin d’accès où l’instance doit être stockée est plus long que MAX_PATH.
LOCALDB_ERROR_CANNOT_ACCESS_INSTANCE_FOLDER Un dossier d’instance n’est pas accessible.
LOCALDB_ERROR_CANNOT_ACCESS_INSTANCE_REGISTRY Un registre d’instances n’est pas accessible.
LOCALDB_ERROR_INSTANCE_CONFIGURATION_CORRUPT Une configuration d'instance est endommagée.
LOCALDB_ERROR_INTERNAL_ERROR Une erreur inattendue s’est produite. Pour plus d'informations, consultez le journal des événements.

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. Sinon, LOCALDB_ERROR_INVALID_PARAMETER est retournée.

Un exemple classique d’utilisation de l’API LocalDBGetInstanceInfo ressemble à ceci :

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

Pour obtenir un exemple de code qui utilise l’API LocalDB, consultez la référence SQL Server Express LocalDB.