executing: use [dbName] ; exec sp_spaceused with ADO C++

  adodb, c++, sql-server

I am trying to determine the size of a full backub using the query:

 use [someDtabase]; exec sp_spaceused  

If I run it in SSMS it works fine, but when I try to repeat it in C ++ code I get the error: "Operation not allowed when object is closed". My code:

std::wstring query = L"use [someDatabase]; exec sp_spaceused";
ADODB::_CommandPtr ptrCommand;
ptrCommand.CreateInstance( __uuidof( ADODB::Command ));
ptrCommand->ActiveConnection = m_ptrConnection;
ptrCommand->CommandText = _bstr_t( query.c_str() );
ptrCommand->CommandTimeout = timeout;
ADODB::_RecordsetPtr ptrRecordset = ptrCommand->Execute( NULL, NULL, ADODB::adCmdText );
if (!ptrRecordset || ptrRecordset->EndOfFile == VARIANT_TRUE) //<--an exception is thrown here

I guess the problem is in the "use [someDtabase];" and the recordset is always closed for it

Source: Windows Questions C++