1

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

5
  • In ADO there are EOF and BOF properties you'll need to check after you open a recordset. msdn.microsoft.com/en-us/library/windows/desktop/… Commented Jun 30, 2014 at 18:17
  • Thanks. WHen I use EOF() I also get the same com_error, that is "“ADODB.Recordset error '800a0e78' Operation is not allowed when the object is closed.? Commented Jun 30, 2014 at 19:18
  • Also I think the recordset should not be empty, since it will always contain one record with the default data path and default log path. Commented Jun 30, 2014 at 19:19
  • What about your ADO connection object? Did you call the .Open() method? Commented Jun 30, 2014 at 20:00
  • Yes, I open the ADO connection to the SQL Server instance successfully. And the m_pRecordset->Open is also successful. But when I call EOF or MoveFirst, then I will get the error. Commented Jun 30, 2014 at 22:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.