共用方式為


LocalDBGetVersionInfo function

Applies to:SQL Server

傳回指定之 SQL Server Express LocalDB 版本的資訊,例如是否存在,以及完整的 LocalDB 版本號碼(包括組建和發行編號)。

資訊會以具名 LocalDBVersionInfo的形式struct傳回,其具有下列定義。

typedef struct _LocalDBVersionInfo
{
      // Contains the size of the LocalDBVersionInfo struct
      DWORD  cbLocalDBVersionInfoSize;

      // Holds the version name
      TLocalDBVersionwszVersion;

      // TRUE if the instance files exist on disk, FALSE otherwise
      BOOL   bExists;

      // Holds the LocalDB version for the instance in the format: major.minor.build.revision
      DWORD  dwMajor;
      DWORD  dwMinor;
      DWORD  dwBuild;
      DWORD  dwRevision;
} LocalDBVersionInfo;

Header file:msoledbsql.h

Syntax

HRESULT LocalDBGetVersionInfo(
           PCWSTR wszVersionName ,
           PLocalDBVersionInfo pVersionInfo ,
           DWORD dwVersionInfoSize);

Arguments

wszVersionName

[輸入]LocalDB 版本名稱。

pVersionInfo

[輸出]用來儲存LocalDB版本相關信息的緩衝區。

dwVersionInfoSize

[Input] Holds the size of the VersionInfo buffer.

Returns

S_OK:函式成功。

Error Description
LOCALDB_ERROR_NOT_INSTALLED 計算機上未安裝 SQL Server Express LocalDB。
LOCALDB_ERROR_INVALID_PARAMETER 一或多個指定的輸入參數無效。
LOCALDB_ERROR_UNKNOWN_VERSION 指定的 LocalDB 版本不存在。
LOCALDB_ERROR_INTERNAL_ERROR 發生未預期的錯誤。 如需詳細資訊,請參閱事件記錄檔。

Details

The rationale behind the introduction of the struct size argument (lpVersionInfoSize) is to enable the API to return different versions of the LocalDBVersionInfostruct, effectively enabling forward and backward compatibility.

If the struct size argument (lpVersionInfoSize) matches the size of a known version of the LocalDBVersionInfostruct, that version of the struct is returned. 否則會傳回 LOCALDB_ERROR_INVALID_PARAMETER

API 使用方式的 LocalDBGetVersionInfo 一般範例如下所示:

LocalDBVersionInfo vi;
LocalDBVersionInfo(L"11.0", &vi, sizeof(LocalDBVersionInfo));

Remarks

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