Thread: Compiler error on database connection

  1. #1
    Registered User
    Join Date
    Oct 2011

    Lightbulb Compiler error on database connection

    Hi all,

    I am having trouble in compiling the code written C language on windows platform.
    The compiler throws error as below,

    test.obj : error LNK2019: unresolved external symbol SQLDriverConnect@32 referenced in function _main test.exe : fatal error LNK1120: 1 unresolved externals

    Source code:

    #include <stdio.h>
    #include <windows.h>
    #include <winnt.h>
    #include <sql.h>
    #include <sqlext.h>
    main() {
    SQLRETURN ret;
    SQLHDBC dbc; /* assume already allocated */
    ret = SQLDriverConnect(dbc, NULL, "DSN=mydsn;", SQL_NTS,
                           NULL, 0, NULL, SQL_DRIVER_COMPLETE);
    Compiler: VS 2010 command line
    cl test.c

    When I try to link the odbc with /link odbc switch in the command line it throws error. Basically, I am not able to find out as how to link odbc.

    Could you anyone please help me out to compile successfully.

    Do we have any step-by-step approch for ODBC connection from c language?


  2. #2
    Join Date
    Aug 2010
    Ontario Canada
    That's a linker error... you need to add the sql libraries to your linker's list.

  3. #3
    Registered User
    Join Date
    Oct 2011
    Since I am new to c programming, it would be very helpful if I get all command line paramenters to complie successfully.

    Where is the list of files available and what are the files to add in the command line?

  4. #4
    train spotter
    Join Date
    Aug 2001
    near a computer
    An unresolved external error usually means you have not included a library or DLL that contains the function you are calling.

    Have you linked your project to odbc32.lib?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Oct 2011
    Just I added the odbc32.lib file with path in the command line and works fine.

    Thank you so CommanTater and novacain for your help.

    -- Sundar

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Database connection problem
    By kandas.soft in forum C++ Programming
    Replies: 9
    Last Post: 07-19-2011, 01:40 AM
  2. create connection to database in C
    By gmalachi in forum C Programming
    Replies: 2
    Last Post: 12-29-2010, 05:33 AM
  3. Database connection...
    By MipZhaP in forum Windows Programming
    Replies: 3
    Last Post: 09-11-2004, 08:36 AM
  4. oracle database connection
    By blue8173 in forum C Programming
    Replies: 1
    Last Post: 03-16-2004, 04:30 PM
  5. connection to database through c++
    By teja22 in forum C++ Programming
    Replies: 1
    Last Post: 10-15-2001, 04:10 AM

Tags for this Thread