Click to See Complete Forum and Search --> : ADO connection to MSAccess


Vandana Sood
July 21st, 2000, 11:36 AM
How do I connect to MS Access using ADO?I used the following function
HRESULT CDBO::OpenConnection(_bstr_t pConnectionString)
{
//ConnectionString should be of the format
//"DSN=;UID="";PWD="";"
int li_Error = 0;
HRESULT lhr;
try
{
if (mPv_pConnectionPtr == NULL)
CREATE_INSTANCE(mPv_pConnectionPtr,Connection);
if ( mPv_pConnectionPtr->State == adStateOpen )
{
return S_FALSE;
}
lhr = mPv_pConnectionPtr->Open(pConnectionString,"","",-1);
}
catch (_com_error pobj_ComError)
{
SetError(pobj_ComError,li_Error);
return lhr;
}
return S_OK;
}
What is the connection string that I need to use?
I tried ("DSN="";UID=Admin;PWD="";") i have no pwd to Access database just default settings.My return ptr is null and I am not able to establish a connection.
Also since access does not have store procedures what command type needcs to be used and how.Can i pass query name into CommandType = adCmdStoredProc?

Johnny101
July 22nd, 2000, 03:16 PM
To use the DSN, UID and PWD way of connecting yuo have to have a DSN setup in the ODBC Manager pointing to that Access file. If you dont' have one, that's fine you can also connect in other ways.

i dont know if this will work in C, but in VB i use one of these:

cn.connectionstring = "Provider=MSDASQL;DBQ=" & path to your mdb file & ";"
or
cn.connectionstring = "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=" & pathtomdb" & ";"




good luck,

John

John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org

Vandana Sood
July 24th, 2000, 08:51 AM
Thank You John.I was able to solve that problem long time back.However I still have a problem.When I compile and execute the program there is no error but I am not able to get any result from the query either.On debug it says ADO could not find the object refeered to by the application.Now my quess is that ADO is not able to locate my SQL query from the database.Why is this so???