I am trying to get the SQL Server default data path via ADO/Visual C++.
I find the SQL statements that will do that in How do I find the data directory for a SQL Server instance?
So I just concat all the statements above into a CString object strStatements, then try to open a recordset as follows:
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open(_bstrt(strStatements), _variant_t((IDispath *)m_pConnection, true), adOpenDymanic, adLockOptimistic, 0);
m_pRecordset->MoveFirst();
The last MoveFirst statement will cause com_error, which said
“ADODB.Recordset error '800a0e78' Operation is not allowed when the object is closed.
It seems that there are no data in the recordset at all. What is the problem?
Thanks