Applies to:SQL Server
傳回指定之 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;
Header file:msoledbsql.h
Syntax
HRESULT LocalDBGetInstanceInfo(
PCWSTR wszInstanceName ,
PLocalDBInstanceInfo pInstanceInfo ,
DWORD dwInstanceInfoSize
);
Arguments
wszInstanceName
[輸入]實例名稱。
pInstanceInfo
[輸出]用來儲存LocalDB實例相關信息的緩衝區。
dwInstanceInfoSize
[Input] Holds the size of the InstanceInfo buffer.
Returns
S_OK:函式成功。
| Error | Description |
|---|---|
| LOCALDB_ERROR_NOT_INSTALLED | 計算機上未安裝 SQL Server Express LocalDB。 |
| LOCALDB_ERROR_INVALID_PARAMETER | 一或多個指定的輸入參數無效。 |
| LOCALDB_ERROR_INVALID_INSTANCE_NAME | 指定的實例名稱無效。 |
| LOCALDB_ERROR_UNKNOWN_INSTANCE | 實例不存在。 |
| LOCALDB_ERROR_INSTANCE_FOLDER_PATH_TOO_LONG | 應該儲存實例的路徑比 長 MAX_PATH。 |
| LOCALDB_ERROR_CANNOT_ACCESS_INSTANCE_FOLDER | 無法存取實例資料夾。 |
| LOCALDB_ERROR_CANNOT_ACCESS_INSTANCE_REGISTRY | 無法存取實例登錄。 |
| LOCALDB_ERROR_INSTANCE_CONFIGURATION_CORRUPT | 實例組態已損毀。 |
| LOCALDB_ERROR_INTERNAL_ERROR | 發生未預期的錯誤。 如需詳細資訊,請參閱事件記錄檔。 |
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. 否則會傳回 LOCALDB_ERROR_INVALID_PARAMETER。
API 使用方式的 LocalDBGetInstanceInfo 一般範例如下所示:
LocalDBInstanceInfo ii;
LocalDBInstanceInfo(L"Test", &ii, sizeof(LocalDBInstanceInfo));
如需使用 LocalDB API 的程式碼範例,請參閱 SQL Server Express LocalDB 參考。