How can I retrieve the queries of a Visual FoxPro database?

Hello experts,

I am using the MFC OLE DB to connect to a Visual FoxPro database, and I am trying to retrieve the queries names of that database, but it didn’t work. Here below the code I used:


     CoInitialize(NULL);
 
     CDataSource dsDataSource;
     HRESULT hr = dsDataSource.Open();

     if(!hr)
     {
          CSession stnSession;
          hr = stnSession.Open(dsDataSource);

          if(!hr)
          {
               CProcedures proc;
               HRESULT hr = proc.Open(stnSession);

               if(!hr)
               {
                    hr = proc.MoveFirst();
 
                    while(!hr)
                    {          
                         MessageBox(proc.m_szName);
                         hr = proc.MoveNext();  
                    }
               }
           }
      }


Does anyone know if the previous code fragment has any problem, or if there is any other way to retrieve the queries names of a Visual FoxPro database?
ASD-JOAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mahesh1402IT ProfessionalCommented:
have you tried using CDatabase ? ie. CDatabase::OpenEx() function to establish the connection, then CRecordset to hold the query data and open the recordset using an SQL statement ?

MAHESH
ASD-JOAuthor Commented:
No, because I need to connect to my databases only using the OLE DB (vfpoledb.1 provider), not the ODBC.
DanRollinsCommented:
When you single-step the code, where does the error occur?
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

ASD-JOAuthor Commented:
Well RanRollins, there is no runtime error occurs, but proc.MoveFirst() returns a nonzero value while it must return zero for a successful call. This happens only with Visual FoxPro databases, but with MS Access, the previous code works successfully, and get the names of the queries.
DanRollinsCommented:
As MDSN indicates...
    The Recordset object must support bookmarks or backward cursor movement; ...

I suppose that FoxPro does nor support that or that you did not specify the right arguments so that the ADO recordset can support it.

The simplest solution would be to skip the MoveFirst() call... When you Open the recordset, it should *start out* positioned at the first record.  Just go right into the:

            while(!hr)   {          
                     MessageBox(proc.m_szName);
                     hr = proc.MoveNext();  
            }  
ASD-JOAuthor Commented:
I tried to skip the MoveFirst() call, but it didn't work.
But i found later that the ODBC FoxPro driver I was using doesn't support retreiving queries. So I replaced it with the OLE DB FoxPro driver and it is working now.
Thank you DanRollins,
GranModCommented:
Closed, 150 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.