【问题标题】:How to enable connection resource pooling with ATL/MSOLEDBSQL?如何使用 ATL/MSOLEDBSQL 启用连接资源池?
【发布时间】:2019-11-01 18:21:03
【问题描述】:

我有 ATL 代码来打开启用了连接资源池的 sql 连接。


    CDBPropSet  dbinit;
    dbinit[0].SetGUID(DBPROPSET_DBINIT);
    dbinit[0].AddProperty(DBPROP_INIT_OLEDBSERVICES, (long)DBPROPVAL_OS_ENABLEALL);
    CDataSource::OpenWithServiceComponents ("SQLNCLI11", dbinit, 1);

编辑
我正在从 SQLNCLI 迁移到 MSOLEDBSQL,以便启用 MULTISUBNETFAILOVER 选项。但是当使用 MSOLEDBSQL 作为 MULTISUBNETFAILOVER 的提供者调用 CDataSource::OpenWithServiceComponents 时出现错误。

    CDBPropSet  dbinit[2];
    dbinit[0].SetGUID(DBPROPSET_DBINIT);
    dbinit[0].AddProperty(DBPROP_INIT_OLEDBSERVICES, (long)DBPROPVAL_OS_ENABLEALL);
    dbinit[1].SetGUID(DBPROPSET_SQLSERVERDBINIT);
    dbinit[1].AddProperty(SSPROP_INIT_MULTISUBNETFAILOVER, VARIANT_TRUE));
    CDataSource db;
    db.OpenWithServiceComponents ("MSOLEDBSQL", dbinit, 2);

    HR=0x80040e21, EXCEPTION_UNKNOWN (0x80040E21), No error info available.

如何在启用 MULTISUBNETFAILOVER 的同时启用 ATL/MSOLEDBSQL 连接资源池?

【问题讨论】:

  • 您有最新版本的 SQL Server 的 OLE DB 驱动程序吗?docs.microsoft.com/en-us/sql/connect/oledb/… 您需要 18.0.2 或更高版本
  • 是的,我正在使用上述链接中的最新驱动程序。当我在 ATLDBCLI 代码 - DB_S_ERRORSOCCURRED Multiple-step operation completed with one or more errors. Check each status value 中进行调试时,我收到了这个错误。我看到 dwstatus 值为 0。
  • 还要添加,CDataSource::Open 返回成功。只有CDataSource::OpenWithServiceComponents 返回失败。
  • SSPROP_INIT_MULTISUBNETFAILOVER 在 DBPROPSET_SQLSERVERDBINIT 中,而不在 DBPROPSET_DBINIT 中
  • 是的。我用 DBPROPSET_SQLSERVERDBINIT 对其进行了初始化。我错过了我提供的样本。现在编辑它以包含相同的

标签: c++ oledb atl


【解决方案1】:

这是由于CDBPropSet 工具类附带的AddProperty 实用方法。您使用 VARIANT_TRUE 这是 OLEDB 的正确值,但它会强制 C++ 编译器使用此重载,因为 VARIANT_TRUE 很短:

bool AddProperty(DWORD dwPropertyID, short nValue, DBPROPOPTIONS propoptions);

所以,只需使用真正的 C++ 布尔值,如下所示:

dbinit[1].AddProperty(SSPROP_INIT_MULTISUBNETFAILOVER, true));

实用程序类将传递一个 VARIANT_TRUE...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-21
    • 1970-01-01
    • 2021-08-29
    • 2019-06-11
    • 2010-10-18
    • 2015-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多