Compartilhar via


LocalDBGetInstanceInfo function

Applies to:SQL Server

Retorna informações para a instância especificada do SQL Server Express LocalDB, como se ela existe, a versão localDB que ela usa, se está em execução e assim por diante.

As informações são retornadas em um struct nome , LocalDBInstanceInfoque tem a definição a seguir.

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

[Entrada] O nome da instância.

pInstanceInfo

[Saída] O buffer para armazenar as informações sobre a instância de LocalDB.

dwInstanceInfoSize

[Input] Holds the size of the InstanceInfo buffer.

Returns

S_OK: a função foi bem-sucedida.

Error Description
LOCALDB_ERROR_NOT_INSTALLED O SQL Server Express LocalDB não está instalado no computador.
LOCALDB_ERROR_INVALID_PARAMETER Um ou mais parâmetros de entrada especificados são inválidos.
LOCALDB_ERROR_INVALID_INSTANCE_NAME O nome de instância especificado é inválido.
LOCALDB_ERROR_UNKNOWN_INSTANCE A instância não existe.
LOCALDB_ERROR_INSTANCE_FOLDER_PATH_TOO_LONG O caminho em que a instância deve ser armazenada é maior que MAX_PATH.
LOCALDB_ERROR_CANNOT_ACCESS_INSTANCE_FOLDER Uma pasta de instância não pode ser acessada.
LOCALDB_ERROR_CANNOT_ACCESS_INSTANCE_REGISTRY Não é possível acessar um registro de instância.
LOCALDB_ERROR_INSTANCE_CONFIGURATION_CORRUPT Uma configuração de instância está corrompida.
LOCALDB_ERROR_INTERNAL_ERROR Erro inesperado. Consulte o log de eventos para obter detalhes.

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. Caso contrário, LOCALDB_ERROR_INVALID_PARAMETER será retornado.

Um exemplo típico de uso de LocalDBGetInstanceInfo API tem esta aparência:

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

Para obter um exemplo de código que usa a API localdb, consulte a referência do SQL Server Express LocalDB.