Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

problem accessing database headers thru C++ program

Posted on 2004-08-16
4
480 Views
Last Modified: 2012-08-13
When i try to run this program

*******************************************
#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 From Makes 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 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 ("\t%s\n", 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;}
*******************************************


i get the following error, i have included odbc.lib, odbccpp.lib and winmm.lib while compiling the program


Warning W8004 DBC.cpp 70: 'retcode' is assigned a value that is never used in function main()
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external 'SQLAllocEnv' referenced from C:\JAVA\JNI\DBC.OBJ
Error: Unresolved external 'SQLAllocConnect' referenced from C:\JAVA\JNI\DBC.OBJ
Error: Unresolved external 'SQLConnect' referenced from C:\JAVA\JNI\DBC.OBJ
Error: Unresolved external 'SQLAllocStmt' referenced from C:\JAVA\JNI\DBC.OBJ
Error: Unresolved external 'SQLPrepare' referenced from C:\JAVA\JNI\DBC.OBJ
Error: Unresolved external 'SQLExecute' referenced from C:\JAVA\JNI\DBC.OBJ
Error: Unresolved external 'SQLBindCol' referenced from C:\JAVA\JNI\DBC.OBJ
Error: Unresolved external 'SQLFetch' referenced from C:\JAVA\JNI\DBC.OBJ
Error: Unresolved external 'SQLFreeStmt' referenced from C:\JAVA\JNI\DBC.OBJ
Error: Unresolved external 'SQLDisconnect' referenced from C:\JAVA\JNI\DBC.OBJ
Error: Unresolved external 'SQLFreeConnect' referenced from C:\JAVA\JNI\DBC.OBJ
Error: Unresolved external 'SQLFreeEnv' referenced from C:\JAVA\JNI\DBC.OBJ
0
Comment
Question by:bhavanigiritharan
  • 2
4 Comments
 
LVL 13

Expert Comment

by:SteH
ID: 11809872
It seems that a library with SQL functions is missing in your build. Add it to the project (to the objects the linker treats).
0
 
LVL 86

Expert Comment

by:jkr
ID: 11810467
More specific: You need to add ODBC32.LIB to your project also.
0
 

Author Comment

by:bhavanigiritharan
ID: 11813975
Thanks a lot for the replies.

I am sorry, this is probably the third program i am trying to run in CPP, other than hello world's..

I am not sure of how to add odbc32.lib to my project.

this is the command i use to compile the code..
c:> bcc32 -I"c:\borland\bcc55\include" -I"c:\java\lcc\lib" -L"c:\borland\bcc55\lib" -okewl  DBC.cpp


where c:\java\c\lcc\lib has odbc32.lib.


0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 11814205
Then you should use

bcc32 -I"c:\borland\bcc55\include" -I"c:\java\lcc\lib" -L"c:\borland\bcc55\lib" -okewl  DBC.cpp odbc32.lib

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
object modeling - load and save functions 5 62
VS2015 compilation and missing DLLs 9 160
Path to  STL Map header file 1 69
C++ :Change value from  DisableCMD registry 4 65
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question