CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2005
    Posts
    25

    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?

  2. #2
    Join Date
    Mar 2001
    Posts
    2,529

    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!

  3. #3
    Join Date
    May 2005
    Posts
    25

    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

  4. #4
    Join Date
    Mar 2001
    Posts
    2,529

    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

  5. #5
    Join Date
    May 2005
    Posts
    25

    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
  •  





Click Here to Expand Forum to Full Width

Featured