-
May 16th, 2005, 09:07 AM
#1
How to check for ODBC driver in C++
I have a project in VC++ that uses an ODBC driver to connect to a database. Is there a way, from code, to check if the driver is installed on a system? Now I know I can just do:
_ConnectionPtr pConnection;
pConnection.CreateInstance(__uuidof(Connection));
try{ pConnection->Open(connectionStr, L"", L"", adConnectUnspecified); }
catch(_com_error& err){// extract error msg here}
the connection string for that example looks something like:
Driver={Microsoft Visual FoxPro Driver};SourceType=DBC;SourceDB=c:\myvfpdb.dbc;Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO
The problem with that connection string is that I have to have the full path and filename to the database. I would like to check for the existance of the driver before I have the path and filename but have been unsuccessful as of yet. If I cannot verify its existance with ADO/ODBC calls is there a system call I can use?
-
May 16th, 2005, 11:15 AM
#2
Re: How to check for ODBC driver in C++
Code:
void CMySQLODBCConn::GetMySQLDriver()
{
char szBuf[2001];
WORD cbBufMax = 2000;
WORD cbBufOut;
char *pszBuf = szBuf;
// Get the names of the installed drivers ("odbcinst.h" has to be included )
if(!SQLGetInstalledDrivers(szBuf,cbBufMax,& cbBufOut))
{
m_sMySQLDriver = "";
}
// Search for the driver...
do
{
if( strstr( pszBuf, "MySQL" ) != 0 )
{
// Found !
m_sMySQLDriver = CString( pszBuf );
break;
}
pszBuf = strchr( pszBuf, '\0' ) + 1;
}
while( pszBuf[1] != '\0' );
}
HTH,
ahoodin
PS If this helps dont forget to rate!
-
May 16th, 2005, 11:52 AM
#3
Re: How to check for ODBC driver in C++
thanks, the code you provided helped ... was still missing an include file but found what I needed here: http://www.thecodeproject.com/database/excel_odbc.asp
-
May 16th, 2005, 12:05 PM
#4
Re: How to check for ODBC driver in C++
Code:
// Get the names of the installed drivers ("odbcinst.h" has to be included )
this header?
ahoodin
-
May 16th, 2005, 01:56 PM
#5
Re: How to check for ODBC driver in C++
Nope, this one: include <afxdb.h>
Last edited by ShadowCoder; May 16th, 2005 at 02:02 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|