Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I am trying to link my c++ console program with the SQL database and i have downloaded the SQL API from sqlapi.com but after putting .lib in additional dependencies,DLL in system 32 and SQLAPI.h in header it still dont work and when i try to include the sqlheader in my program it shows error and also it shows another error of sqlapi.dll? can anybody explain me the process to use SQL API in visualC++.


/thanks in advance
Posted
Comments
Malli_S 31-Jul-12 4:44am    
Include the SQlAPI.h file path in you project settings 'Additional Include Folder Path'. And for dll problem, you may have to copy the dll at the path where the your project exe is generated.
Richard MacCutchan 31-Jul-12 5:38am    
it still dont work and when i try to include the sqlheader in my program it shows error and also it shows another error of sqlapi.dll?
Unless you you provide the exact error messages and the lines of code that cause them you will not get much help. Try to help yourself by providing proper details with your question.
meshinator 31-Jul-12 7:41am    
Thanks Malli,this was first time i was using SQL API and i forgot to gib the path.
Malli_S 31-Jul-12 10:24am    
You're welcome!

Based on OP's comment Thanks Malli,this was first time i was using SQL API and i forgot to gib the path., it looks like issue is resolved.

Posting just to pop it out of unanswered list.
 
Share this answer
 
You can also try the ODBC ..

take a example:

#include <windows.h>
#include <sqlext.h>
#include <stdio.h>

int main(void)

{
HENV hEnv = NULL; // Env Handle from SQLAllocEnv()
HDBC  hDBC = NULL; // Connection handle
HSTMT hStmt = NULL; // Statement handle
UCHAR szDSN[SQL_MAX_DSN_LENGTH] ="db97";   // Data Source Name buffer
UCHAR* szUID = NULL; // User ID buffer
UCHAR* szPasswd = NULL;// Password buffer
UCHAR  szModel[128]; // Model buffer
SDWORD  cbModel; // Model buffer bytes recieved
UCHAR   szSqlStr[] = "Select Model FromMakes Where Make='Vauxhall'";                // SQL string
 RETCODE              retcode; // Return code

// Allocate memory for ODBC Environment handle
SQLAllocEnv (&hEnv);

// Allocate memory for the connection handle
 SQLAllocConnect (hEnv, &hDBC);

// Connect to the data source "db97" using userid andpassword.
retcode = SQLConnect (hDBC, szDSN, SQL_NTS, szUID,SQL_NTS, szPasswd, SQL_NTS);

 if (retcode == SQL_SUCCESS || retcode ==SQL_SUCCESS_WITH_INFO)
 {
    // Allocate memory for the statementhandle
    retcode = SQLAllocStmt (hDBC, &hStmt);

    // Prepare the SQL statement by assigningit to the statement handle
    retcode = SQLPrepare (hStmt, szSqlStr,sizeof (szSqlStr));

    // Execute the SQL statement handle
    retcode = SQLExecute (hStmt);

    // Project only column 1 which is themodels
    SQLBindCol (hStmt, 1, SQL_C_CHAR, szModel,sizeof(szModel), &cbModel);

    // Get row of data from the result setdefined above in the statement
    retcode = SQLFetch (hStmt);

    while (retcode == SQL_SUCCESS || retcode== SQL_SUCCESS_WITH_INFO)
    {
         printf ("%s",szModel);                      // Print row(model)
        retcode = SQLFetch(hStmt);              // Fetch next row from result set
    }

    // Free the allocated statement handle
    SQLFreeStmt (hStmt, SQL_DROP);

    // Disconnect from datasource
    SQLDisconnect (hDBC);

}


// Free the allocated connection handle
SQLFreeConnect (hDBC);

// Free the allocated ODBC environment handle
SQLFreeEnv (hEnv);

return 0;

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900