connect to an access .accdb database using a c# activeX object in Windows 7 and CVI 9.0.1

538 Views Asked by At

I am trying to connect to an access .accdb database using a 32 activeX object in CVI 9.0.1. I am able to connect just fine to a .mdb file, but when I try .accdb the function goes through just fine, but connectFlag returns a 0 indicating it failed to connect to the file. I am able to use the exact same code in WindowsXP, and it works just fine for both .accdb and .mdb files. I have verified that the access drivers do exist in C:\Windows\SysWOW64\odbcad32.exe

Microsoft Accees Driver (*.mdb, *.accdb) version 14.00.7010.1000

I am also able to connect to the same database on my windows 7 machine using Visual Studio 2010. I also downloaded a trial of CVI SqlTool Kit, and was able to connect to the .accdb database using a DSN. I have also downloaded a copy of CVI 2013 thinking maybe my version only running in 32-bit and not able to see the SysWOW64 folder, however I got the same results in CVI 2013.

I have included the code below....

HRESULT result = 0;
ERRORINFO errorStruct;
char * dbPtr = NULL;
char * SQLptr = NULL;
char * record = NULL;
VBOOL connectFlag;
CAObjHandle databaseObj = 0;  
// database connection strings
char dbLocation[] = "DSN=test"  ;
char dbLocation[] = "c:\\obsoleteparts.mdb" ;
char dbLocation[] = "c:\\serialnumbers.accdb"   ;
char sqlStr[]= "SELECT tblSerialNumbers.serialNumber FROM(tblSerialNumbers) WHERE tblSerialNumbers.prefix='05-' ORDER BY tblSerialNumbers.serialNumber DESC";
prjAxDatabaseObj__Recordset rsObj;

dbPtr =  dbLocation;
SQLptr = sqlStr;
errorTxt[0] = 0;

result = prjAxDatabase_New_axDatabase (NULL, 1, LOCALE_NEUTRAL, 0,&databaseObj );
result = prjAxDatabase__axDatabaseConnect (databaseObj, &errorStruct, &dbPtr, &connectFlag);
CA_DisplayErrorInfo (databaseObj,"error",result,&errorStruct)      

Code runs just fine, does not display an error, result shows that the operation was a success, however the connectFlag returns a 0 meaning it did not connect. Any suggestions would be much appreciated thanks.

-Justin

1

There are 1 best solutions below

0
On

Regarding my comment above, I used the following connect strings (when not using DSNs) for all CVI versions:

//giAmsIndex = DBConnect ("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\\dev\\DB\\New_AMS_Index.accdb");
//giAmsData = DBConnect (""Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\\dev\\DB\\New_AMS_000");  

and the following when using DSNs:

hAmsIndex   = DBConnect ("DSN=New_AMS_Index");
hAmsData    = DBConnect ("DSN=New_AMS_000");

But as I said in the comment, your problem description suggests UAC issues having to do with MS Access.