LocalDBGetInstanceInfo 函数

返回有关指定的 SQL Server Express LocalDB 实例的信息,如该实例是否存在、实例使用的 LocalDB 版本以及实例是否正在运行等。

将在 struct 命名 LocalDBInstanceInfo 中返回该信息,该信息具有以下定义。

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 标头信息和版本信息