c++ accessing a msaccess db 2003 with c++ vs2003

when the system gets to this line the
hr = dbDataSource.OpenFromInitializationString(lpcOleConnect);
this is my connection string
-      lpcOleConnect      0x00430860 "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\c++ tree view\new files\DB\TreeView.mdb;User Id=admin;Password=;"      unsigned short*
but will not connect. have not done this before so this is all new to me and have no working examples to have a look at
any help would be appreciaed

// This is the main project file for VC++ application project
// generated using an Application Wizard.

#include "stdafx.h"
#include  <atldbcli.h>
#include  <atldbsch.h>
#include <ostream>
#include <iostream>
#include <string>
#include <wtypes.h>

#using <mscorlib.dll>

using namespace System;
using namespace std;

int _tmain()
    // TODO: Please replace the sample code below with your own.
    HRESULT hr = 0;
    std::string str;
    int i=0, ret=0;
  //  std::string query;
      string DAM;
      LPCOLESTR lpcOleConnect = L"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\c++ tree view\\new files\\DB\\TreeView.mdb;User Id=admin;Password=;";

                  // To initialize the connection to a database using an OLE DB provider,
            // two ATL classes are needed: CDataSource and CSession.
            CDataSource dbDataSource;
            CSession dbSession;

            // Uses ATL's string conversion macros to convert between character encodings.

            // Open the connection and initialize the data source specified by the passed
            // initialization string.
// **************************************************************************************************
//******************  falls over here
            hr = dbDataSource.OpenFromInitializationString(lpcOleConnect);
            if (FAILED(hr))
                  cout<<DAM<<": Unable to connect to data source "<<OLE2T(lpcOleConnect)<<endl;
      //      else
      //      {
                  hr = dbSession.Open(dbDataSource);
//                  if (FAILED(hr))
//                  {
      //                  cout<<DAM<<": Couldn't create session on data source "<<OLE2T(lpcOleConnect)<<endl;
//                  }
//                  else
//                  {
                        CComVariant var;
                        hr = dbDataSource.GetProperty(DBPROPSET_DATASOURCEINFO, DBPROP_DATASOURCENAME, &var);
//                        if (FAILED(hr) || (var.vt == VT_EMPTY))
//                        {
//                              cout<<DAM<<": No Data Source Name Specified."<<endl;
//                        }
//                        else
//                        {
//                              cout<<DAM<<": Successfully connected to database. Data source name:\n  "
//                                    <<COLE2T(var.bstrVal)<<endl;
                              // Prepare SQL query.
                              LPCOLESTR query = L"SELECT ParentTable.ParentId, ParentTable.ParentName FROM ParentTable;";
//                              cout<<DAM<<": SQL query:\n  "<<OLE2T(query)<<endl;

                              // Excecute the query and create a record set.
                              CCommand<CDynamicStringAccessor> cmd;
                              hr = cmd.Open(dbSession, query);
                              DBORDINAL colCount = cmd.GetColumnCount();
//                              if (SUCCEEDED(hr) && 0 < colCount)
//                              {
//                                    cout<<DAM<<": Retrieve schema info for the given result set: "<<endl;
                                    DBORDINAL cColumns;
                                    DBCOLUMNINFO* rgInfo = NULL;
                                    OLECHAR* pStringsBuffer = NULL;
                                    cmd.GetColumnInfo(&cColumns, &rgInfo, &pStringsBuffer);
                                    for (int col=0; col < (int)colCount; col++)
                                          cout<<" | "<<OLE2T(rgInfo[col].pwszName);

//                                    cout<<DAM<<": Fetch the actual data: "<<endl;
                                    int rowCount = 0;
                                    CRowset<CDynamicStringAccessor>* pRS = (CRowset<CDynamicStringAccessor>*)&cmd;
                                    // Loop through the rows in the result set.
                                    while (pRS->MoveNext() == S_OK)
                                          for (int col=1; col <= (int)colCount; col++)
                                                CHAR* szValue = cmd.GetString(col);
                                                cout<<" | "<<szValue;
//                                    cout<<DAM<<": Total Row Count: "<<rowCount<<endl;
//                                    cout<<DAM<<": Error: Number of fields in the result set is 0."<<endl;
//                        }  
//                  }
      //      }

//            cout<<DAM<<": Cleanup. Done."<<endl;

      return 0;
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.

That's a provider for an accdb file used by Access 2007+
msaccess db 2003
If it is an mdb file, you need the JET provider string.


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
sydneyguyAuthor Commented:
spot on good set of eyes

      LPCOLESTR lpcOleConnect = L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\c++ tree view\\new files\\DB\\TreeView.mdb;User Id=admin;;Password=;";

access the DB nbow i just have to return the information
thanks for the help
sydneyguyAuthor Commented:
worked brillaint thenks
No problem.
The other solution would be to use
instead of TreeView.mdb -- but I suspect that VS generated the file, so leaving that alone and getting the provider string right was the much better choice anyway!

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

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.