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 参考。