共用方式為


LocalDBGetInstanceInfo 函數

傳回指定之 SQL Server Express LocalDB 執行個體的資訊,例如執行個體是否存在、執行個體使用的 LocalDB 版本、執行個體是否正在執行等等。

此資訊會以名為 LocalDBInstanceInfo 的 struct 傳回,其定義如下。

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;

**標頭檔:**sqlncli.h

語法

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

參數

  • wszInstanceName
    [輸入] 執行個體名稱。

  • pInstanceInfo
    [輸出] 儲存 LocalDB 執行個體資訊的緩衝區。

  • dwInstanceInfoSize
    [輸入] 保存 InstanceInfo 緩衝區的大小。

傳回值

詳細資料

導入 struct 大小引數 (lpInstanceInfoSize) 背後的基本原理,是為了啟用 API 以傳回 LocalDBInstanceInfo struct 的不同版本,以有效地啟用新舊版相容性。

如果 struct 大小引數 (lpInstanceInfoSize) 符合 LocalDBInstanceInfo struct 已知版本的大小,則會傳回該版本的 struct。 否則會傳回 LOCALDB_ERROR_INVALID_PARAMETER。

LocalDBGetInstanceInfo API 使用方式的典型範例如下所示:

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

如需使用 LocalDB API 的程式碼範例,請參閱<SQL Server Express LocalDB 參考>。

請參閱

概念

SQL Server Express LocalDB 標頭和版本資訊