[RESOLVED] VC++ 6 connecting to Access db via ADO problems

The problem is I can't.

The company has been using DAO for the past umpteen years, but DAO won't work with multi-threaded applications.

But I needed to connect to an Access database and read some values out. I didn't need to port the entire superset of functionality across, so I decide to hack out part of the functionality. I quickly hit code guru and codeproject for simple libraries and after a quick scanning it seemed to me that Tim Kohler is MFC ADO Wrapper (http://www.codeproject.com/database/adoclasses.asp) classes were ideal.

So I quickly added in what functionality I needed and tried to connect to the database. Unfortunately I couldn't. A quick attack of his code gave me the error. The error I got was "Unspecified error". Hmm helpful. A bit of messing with the connection strings gave me an "IDispatch error #3187" error.

The interweb didn't turn up much on it so I decide to go back to basics and write one myself. Just to connect and nothing else and I got the previous two errors plus the "Unknown Error 0x800A0E7A" with various tweaking of the connection and provider.

In the end I decided it might be the database I was trying to connect to - the one I was trying to connect to had a long path name (about 40 characters and two of the paths had spaces) as well as the database was passworded but had no username.

The test database was in the root of C:, had 1 table with 2 columns and 5 rows.

Still I couldn't connect - the same several errors I had earlier with various incarnations of the connect string.

Is there an easy test to see if ADO is working on my PC, or can anyone give any reason why this doesn't work on my machine?

Thanks, Graham Reeds

The code:
HRESULT hr = ::CoInitialize(NULL);
if (FAILED(hr))
{
return false;
}
_ConnectionPtr pConnection;
hr = pConnection.CreateInstance(__uuidof(Connection));
if (FAILED(hr))
{
return false;
}

try
{
CString strProvider("Microsoft.JET.OLEDB.4.0");
m_strDatabasePath = "c:\\db1.mdb";
CString strConnection;
strConnection.Format("Provider=%s;"
"DataSource=%s;"
"Uid=%s;"
"Pwd=%s;",
strProvider,
m_strDatabasePath,
"",
"");
pConnection->Open(_bstr_t(strConnection), _bstr_t(""), _bstr_t(""), adOpenUnspecified);
// ...
}
catch (_com_error e)
{
CString strErr(e.ErrorMessage());
::CoUninitialize();
// ...
}
[2647 byte] By [grahamr -work] at [2007-11-19 23:11:38]
# 1 Re: [RESOLVED] VC++ 6 connecting to Access db via ADO problems
three tasks must be accomplished with ADO:

creating an instances of the _ConnectionPtr, _CommandPtr, and
_RecordsetPtr.

it would be helpful to know just where your attempts are failing.
jim enright at 2007-11-9 13:43:54 >
# 2 Re: [RESOLVED] VC++ 6 connecting to Access db via ADO problems
is use somthing on the order of

ConnectionString = L"dsn=AppMetaData;uid=Admin;";

for my stuff but i set up the ODBC alias via the Control Panel. hope this
helps
jim enright at 2007-11-9 13:44:54 >
# 3 Re: [RESOLVED] VC++ 6 connecting to Access db via ADO problems
I managed to get it working (connecting) dead on 5.30pm as we were due to go home via code found on the MS website using a fully fledged connection string.

Breaking the connection string out to individual sections still fails, but setting ConnectionString and leaving the fields of Open empty works.

So I extended this to Tim Kohler's code by overriding the Open function and doing the same.
grahamr -work at 2007-11-9 13:45:53 >