khaldoun KASSEM
February 8th, 2005, 01:02 PM
I am using the ODBC access driver to request an access database.
My application works very well when I have admin rights and I have no problem
but if I login in without the admin rights (or power user rights) i get a message "Driver's SQLSetConnectAttr failed" "ISAM Driver not found", and the application asks me for the DSN, I choose it but this doesn't work and i get the same message.
I am using VC++6.0, Windows XP Pro, Access 2000.
UINT CHSQL::CreateMSAccessDSN(CString sDbFilePath, CString sDSNName)
{
WIN32_FIND_DATA cFindData;
if(INVALID_HANDLE_VALUE==FindFirstFile((CString)sDbFilePath,&cFindData))
{
AfxMessageBox("Cannot find the file: "+sDbFilePath);
return FALSE;
}
CString mdbpath=(CString)sDbFilePath;
char* szDesc;
int mlen;
szDesc=new char[256];
sprintf(szDesc,"DSN=%s: DESCRIPTION=: FIL=MicrosoftAccess: DEFAULTDIR=: DBQ=%s\0",
sDSNName,mdbpath);
mlen = strlen(szDesc);
int numPath=0;
for (int i=0; i<mlen; i++)
{
if(numPath==4)
continue;
if (szDesc[i] == ':')
{
szDesc[i] = '\0';
numPath++;
}
}
if (FALSE == SQLConfigDataSource(NULL,ODBC_ADD_SYS_DSN,"Microsoft Access Driver (*.mdb)\0",(LPCSTR)szDesc))
{
AfxMessageBox("Cannot create datasource");
return FALSE;
}
return TRUE;
}
CHSQL *g_ODBCConnection;
int OpenDatabase(CString sDatabaseName,CString sPassword, BOOL bReadOnly)
{
int nRet = 0;
CString sDBPath = sDatabaseName;
CString sDSN = _T("DB_BI");
CHSQL::CreateMSAccessDSN(sDBPath,sDSN);
if(!g_ODBCConnection)
{
g_ODBCConnection = new CHSQL();
}
g_ODBCConnection->open(sDSN,sPassword,bReadOnly);
return nRet;
}
void CHSQL::open(CString DSN,CString sPassword,BOOL bReadOnly)
{
DSN="DSN="+DSN + _T(";pwd=") + sPassword;
DWORD dwOptions = 0;
if(bReadOnly)
{
dwOptions = CDatabase::openReadOnly;
}
m_Database.OpenEx( _T(DSN),dwOptions);
}
when I call the OpenEx method, it fails.
any Idea
My application works very well when I have admin rights and I have no problem
but if I login in without the admin rights (or power user rights) i get a message "Driver's SQLSetConnectAttr failed" "ISAM Driver not found", and the application asks me for the DSN, I choose it but this doesn't work and i get the same message.
I am using VC++6.0, Windows XP Pro, Access 2000.
UINT CHSQL::CreateMSAccessDSN(CString sDbFilePath, CString sDSNName)
{
WIN32_FIND_DATA cFindData;
if(INVALID_HANDLE_VALUE==FindFirstFile((CString)sDbFilePath,&cFindData))
{
AfxMessageBox("Cannot find the file: "+sDbFilePath);
return FALSE;
}
CString mdbpath=(CString)sDbFilePath;
char* szDesc;
int mlen;
szDesc=new char[256];
sprintf(szDesc,"DSN=%s: DESCRIPTION=: FIL=MicrosoftAccess: DEFAULTDIR=: DBQ=%s\0",
sDSNName,mdbpath);
mlen = strlen(szDesc);
int numPath=0;
for (int i=0; i<mlen; i++)
{
if(numPath==4)
continue;
if (szDesc[i] == ':')
{
szDesc[i] = '\0';
numPath++;
}
}
if (FALSE == SQLConfigDataSource(NULL,ODBC_ADD_SYS_DSN,"Microsoft Access Driver (*.mdb)\0",(LPCSTR)szDesc))
{
AfxMessageBox("Cannot create datasource");
return FALSE;
}
return TRUE;
}
CHSQL *g_ODBCConnection;
int OpenDatabase(CString sDatabaseName,CString sPassword, BOOL bReadOnly)
{
int nRet = 0;
CString sDBPath = sDatabaseName;
CString sDSN = _T("DB_BI");
CHSQL::CreateMSAccessDSN(sDBPath,sDSN);
if(!g_ODBCConnection)
{
g_ODBCConnection = new CHSQL();
}
g_ODBCConnection->open(sDSN,sPassword,bReadOnly);
return nRet;
}
void CHSQL::open(CString DSN,CString sPassword,BOOL bReadOnly)
{
DSN="DSN="+DSN + _T(";pwd=") + sPassword;
DWORD dwOptions = 0;
if(bReadOnly)
{
dwOptions = CDatabase::openReadOnly;
}
m_Database.OpenEx( _T(DSN),dwOptions);
}
when I call the OpenEx method, it fails.
any Idea