Home Dashboard Directory Help

Problem with c++ class CDatabase function GetConnect() by Frekers


 as Duplicate Help for as Duplicate

Sign in
to vote
Type: Bug
ID: 765395
Opened: 9/29/2012 2:02:49 PM
Access Restriction: Public
User(s) can reproduce this bug


The funciton GetConnect() returns always empty string (connection to database is okay).

the function BOOL CDatabase::Connect(DWORD dwOptions) has changed (see below), the variable m_strConnect is set to empty string:

DATA_BLOB connectBlob;
connectBlob.pbData = (BYTE *)(LPCTSTR)m_strConnect;
connectBlob.cbData = (DWORD)(AtlStrLen(m_strConnect) + 1) * sizeof(TCHAR);
    if (CryptProtectData(&connectBlob, NULL, NULL, NULL, NULL, 0, &m_blobConnect))
        SecureZeroMemory((BYTE *)(LPCTSTR)m_strConnect, m_strConnect.GetLength() * sizeof(TCHAR));

The functiont GetConnect() returns the variable m_strConnect, which is empty. In some cases I need the connection string in my application.
Sign in to post a comment.
Posted by Microsoft on 12/18/2012 at 11:01 AM

Thanks for the report. This issue has been fixed in MFC for the next major release of Visual Studio.

Pat Brenner
Visual C++ Libraries Development
Posted by Microsoft on 10/1/2012 at 12:47 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 9/30/2012 at 6:23 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by BongoVR on 7/2/2013 at 3:49 AM
Derive a class from CDatabase and implement a new method to get the connection string like this:

CString CDatabaseEx::GetTrueConnectionString() const
    DATA_BLOB connectBlob;
    if (CryptUnprotectData(const_cast<DATA_BLOB*>(&m_blobConnect), NULL, NULL, NULL, NULL, 0, &connectBlob))
        CString ret = (LPTSTR)connectBlob.pbData;

        return ret;
        return _T("");

Use this class when you otherwise would use CDatabase.
Inside a CRecordset derived class cast the CDatabase* m_pDatabase to (CDatabaseEx*) and use the above function where needed. Since there are no additional data members, the cast is ugly but safe.