Compiler error on database connection

This is a discussion on Compiler error on database connection within the C Programming forums, part of the General Programming Boards category; Hi all, I am having trouble in compiling the code written C language on windows platform. The compiler throws error ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    3

    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:

    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?

    Thanks,
    Sundar

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    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
    Posts
    3
    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
    Location
    near a computer
    Posts
    3,859
    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
    Posts
    3
    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, 02: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, 09: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, 05:10 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21