I want to use database for one of my project instead of Flat Files. But, I am facing some problem connecting C Program to Database. I tried and searched for problem for almost 4 hours now.
*Configuration :* - I am using *Windows XP* as OS - *Dev -C++* as Compiler (it uses gcc in backend I guess) - *MySQL* Database - *ODBC* is set-up and running properly *The Problem :* I am unable to tell the Linker where the ODBC library file is (this is what I can get from searches). Here is the *Error Log* : Compiler: Default compiler Executing g++.exe... g++.exe "E:\db_conn.cpp" -o "E:\db_conn.exe" -g3 -I"C:\Dev-Cpp\include\c++" -I"C:\Dev-Cpp\include\c++\mingw32" -I"C:\Dev-Cpp\include\c++\backward" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" C:\DOCUME~1\ME62CF~1\LOCALS~1\Temp/ccgtaaaa.o(.text+0x12f): In function `main': E:/db_conn.cpp:32: undefined reference to `sqlalloc...@4' C:\DOCUME~1\ME62CF~1\LOCALS~1\Temp/ccgtaaaa.o(.text+0x141):E:/db_conn.cpp:35: undefined reference to `sqlallocconn...@8' C:\DOCUME~1\ME62CF~1\LOCALS~1\Temp/ccgtaaaa.o(.text+0x15f):E:/db_conn.cpp:39: undefined reference to `sqlconn...@28' C:\DOCUME~1\ME62CF~1\LOCALS~1\Temp/ccgtaaaa.o(.text+0x191):E:/db_conn.cpp:44: undefined reference to `sqlallocs...@8' C:\DOCUME~1\ME62CF~1\LOCALS~1\Temp/ccgtaaaa.o(.text+0x1af):E:/db_conn.cpp:47: undefined reference to `sqlprep...@12' C:\DOCUME~1\ME62CF~1\LOCALS~1\Temp/ccgtaaaa.o(.text+0x1c4):E:/db_conn.cpp:51: undefined reference to `sqlexec...@4' C:\DOCUME~1\ME62CF~1\LOCALS~1\Temp/ccgtaaaa.o(.text+0x1f0):E:/db_conn.cpp:54: undefined reference to `sqlbind...@24' C:\DOCUME~1\ME62CF~1\LOCALS~1\Temp/ccgtaaaa.o(.text+0x1fe):E:/db_conn.cpp:58: undefined reference to `sqlfe...@4' C:\DOCUME~1\ME62CF~1\LOCALS~1\Temp/ccgtaaaa.o(.text+0x240):E:/db_conn.cpp:63: undefined reference to `sqlfe...@4' C:\DOCUME~1\ME62CF~1\LOCALS~1\Temp/ccgtaaaa.o(.text+0x259):E:/db_conn.cpp:67: undefined reference to `sqlfrees...@8' C:\DOCUME~1\ME62CF~1\LOCALS~1\Temp/ccgtaaaa.o(.text+0x267):E:/db_conn.cpp:70: undefined reference to `sqldisconn...@4' C:\DOCUME~1\ME62CF~1\LOCALS~1\Temp/ccgtaaaa.o(.text+0x275):E:/db_conn.cpp:75: undefined reference to `sqlfreeconn...@4' C:\DOCUME~1\ME62CF~1\LOCALS~1\Temp/ccgtaaaa.o(.text+0x283):E:/db_conn.cpp:78: undefined reference to `sqlfree...@4' Execution terminated *The Program :* I am attaching the program with the mail. If anyone could help please reply. Its bit important for me. Best. -- Ankit Aggarwal Proud Member of CLUBMCA <http://bit.ly/d1Hrbj> ---------- // Testing the Database Connectivity of C - Dev C++ ;) #include<windows.h> #include<stdio.h> #include<sql.h> #include<sqltypes.h> #include<sqlext.h> int main() { HENV hEnv = NULL; // Env Handle from SQLAllocEnv() HDBC hDBC = NULL; // Connection handle HSTMT hStmt = NULL; // Statement handle UCHAR szDSN[SQL_MAX_DSN_LENGTH] = "odbc_demo"; // 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 * From jos_categories"; // 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 and password. 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 statement handle retcode = SQLAllocStmt (hDBC, &hStmt); // Prepare the SQL statement by assigning it to the statement handle retcode = SQLPrepare (hStmt, szSqlStr, sizeof (szSqlStr)); // Execute the SQL statement handle retcode = SQLExecute (hStmt); // Project only column 1 which is the models SQLBindCol (hStmt, 1, SQL_C_CHAR, szModel,sizeof(szModel), &cbModel); // Get row of data from the result set defined above in the statement retcode = SQLFetch (hStmt); while (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) { printf(" %s ", szModel); // Print row 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; } [Non-text portions of this message have been removed]
