How to enable connection resource pooling with ATL/MSOLEDBSQL?

1

I have ATL code to open sql connection with connection resource pooling enabled.


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

EDIT
I'm in the process of migrating from SQLNCLI to MSOLEDBSQL, inorder to enable MULTISUBNETFAILOVER option. But I get error when CDataSource::OpenWithServiceComponents is invoked with MSOLEDBSQL as the provider with MULTISUBNETFAILOVER.

    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.

How do I enable connection resource pooling with ATL/MSOLEDBSQL along with MULTISUBNETFAILOVER enabled?

c++
oledb
atl
asked on Stack Overflow Jun 19, 2019 by maheshsarma • edited Jun 26, 2019 by maheshsarma

1 Answer

1

This is due to the AddProperty utility method that comes with the CDBPropSet tool class. You use VARIANT_TRUE which is the correct value for OLEDB but it forces the C++ compiler to use this overload because VARIANT_TRUE is a short:

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

So, just use a true C++ bool, like this:

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

And the utility class will pass a VARIANT_TRUE...

answered on Stack Overflow Jun 26, 2019 by Simon Mourier

User contributions licensed under CC BY-SA 3.0