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

Community
  • 1
  • 1
alancc
  • 487
  • 2
  • 24
  • 68
  • In `ADO` there are `EOF` and `BOF` properties you'll need to check after you open a recordset. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675787(v=vs.85).aspx – Dave Mason Jun 30 '14 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.? – alancc Jun 30 '14 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. – alancc Jun 30 '14 at 19:19
  • What about your ADO connection object? Did you call the .Open() method? – Dave Mason Jun 30 '14 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. – alancc Jun 30 '14 at 22:41

0 Answers0