Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Couldn't connect to driver

Couldn't connect to driver

Couldn't connect to driver

I get the following error with the code below it:

Direct ODBC: Couldn't connect to Driver


char szDSN[256] = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ=C:\\Users\\Sasuke\\Documents\\Database1.accdb;";

//LPCTSTR lpszConnect = _T("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ=C:\\Users\\Sasuke\\Documents\\Database1.accdb;");


//int main()
/* Data Access Method used in this sample */
const char* DAM = "Direct ODBC";

HENV    hEnv;
HDBC    hDbc;

/* ODBC API return status */

int     iConnStrLength2Ptr;
char    szConnStrOut[256];

const SQLCHAR* query = (SQLCHAR*)"SELECT * FROM LivePlayers;";

SQLCHAR         chval1[128], chval2[128], colName[128];
int             ret1;
int             ret2;

/* Number of rows and columns in result set */
SQLINTEGER      rowCount = 0;
SQLSMALLINT     fieldCount = 0, currentField = 0;
HSTMT           hStmt;

/* Allocate an environment handle */
rc = SQLAllocEnv(&hEnv);
/* Allocate a connection handle */
 rc = SQLAllocConnect(hEnv, &hDbc);

/* Connect to the 'Northwind 2007.accdb' database */
 rc = SQLDriverConnect(hDbc, NULL, (unsigned char*)szDSN,
    SQL_NTS, (unsigned char*)szConnStrOut,
    255, (SQLSMALLINT*)&iConnStrLength2Ptr, SQL_DRIVER_NOPROMPT);
    printf("%s: Successfully connected to database. Data source name: \n  %s\n",
       DAM, szConnStrOut);

    /* Prepare SQL query */
    printf("%s: SQL query:\n  %s\n", DAM, query);

   rc = SQLAllocStmt(hDbc,&hStmt);
  rc = SQLPrepare(hStmt, (SQLCHAR*)query, SQL_NTS);
    /* Bind result set columns to the local buffers */
     rc = SQLBindCol(hStmt, 1, SQL_C_CHAR, chval1, 128, (SQLINTEGER*)&ret1);
     rc = SQLBindCol(hStmt, 2, SQL_C_CHAR, chval2, 128, (SQLINTEGER*)&ret2);
    /* Excecute the query and create a record set */
  rc = SQLExecute(hStmt);
    if (SQL_SUCCEEDED(rc))
        printf("%s: Retrieve schema info for the given result set:\n", DAM);
        SQLNumResultCols(hStmt, &fieldCount);
        if (fieldCount > 0)
            for (currentField=1; currentField <= fieldCount; currentField++)
                SQLDescribeCol(hStmt, currentField, colName, sizeof(colName), 0, 0, 0, 0, 0);
                printf(" | %s", colName);    
            printf("%s: Error: Number of fields in the result set is 0.\n", DAM);

        printf("%s: Fetch the actual data:\n", DAM);
        /* Loop through the rows in the result set */
        rc = SQLFetch(hStmt);
        while (SQL_SUCCEEDED(rc))
            printf(" | %s | %s\n", chval1, chval2);
            rc = SQLFetch(hStmt);

        printf("%s: Total Row Count: %d\n", DAM, rowCount);
       rc = SQLFreeStmt(hStmt, SQL_DROP);
    printf("%s: Couldn't connect to %s.\n", DAM, szDSN);

/* Disconnect and free up allocated handles */
SQLFreeHandle(SQL_HANDLE_DBC, hDbc);
SQLFreeHandle(SQL_HANDLE_ENV, hEnv);

printf("%s: Cleanup. Done.\n", DAM);
cout << "%s: Cleanup. Done.\n" << endl;

I'm using access 2010, so what's missing here?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close