Partager via


Fonction LocalDBGetInstanceInfo

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 structlocalDBInstanceInfo nommé, 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;  
  

Fichier d’en-tête : sqlncli.h

Syntaxe

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

Paramètres

wszInstanceName
[Entrée] Nom de l’instance.

pInstanceInfo
[Sortie] Mémoire tampon pour stocker les informations relatives à l’instance LocalDB.

dwInstanceInfoSize
[Entrée] Contient la taille de la mémoire tampon InstanceInfo .

Retours

S_OK
La fonction a réussi.

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
Le chemin d’accès où l’instance doit être stockée est plus long que MAX_PATH.

LOCALDB_ERROR_CANNOT_ACCESS_INSTANCE_FOLDER
Impossible d’accéder à un dossier d’instance.

LOCALDB_ERROR_CANNOT_ACCESS_INSTANCE_REGISTRY
Impossible d’accéder à un registre d’instances.

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.

Détails

La justification de l’introduction de l’argument struct de taille (lpInstanceInfoSize) consiste à permettre à l’API de retourner différentes versions de LocalDBInstanceInfostruct, ce qui permet efficacement la compatibilité descendante et descendante.

Si l’argument struct de taille (lpInstanceInfoSize) correspond à la taille d’une version connue de LocalDBInstanceInfostruct, cette version est struct retournée. Sinon, LOCALDB_ERROR_INVALID_PARAMETER est retourné.

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.

Voir aussi

Informations sur l’en-tête et la version SQL Server Express LocalDB