Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 ODBC with C++ to SQL
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
impactblu




PostPosted: Thu Jul 28, 2011 1:20 pm   Post subject: ODBC with C++ to SQL

Hi,

I'm having a hard time getting this program to work. I'm trying to get this ODBC program to work with SQL but I get a lot of PDB errors and i'm not sure what to do about those.
here is my code

code:


#include <iostream>
#include <windows.h>
#include <sqltypes.h>
#include <sql.h>
#include <sqlext.h>

using namespace std;

void show_error(unsigned int handletype, const SQLHANDLE& handle){
    SQLCHAR sqlstate[1024];
    SQLCHAR message[1024];
    if(SQL_SUCCESS == SQLGetDiagRec(handletype, handle, 1, sqlstate, NULL, message, 1024, NULL))
        cout<<"Message: "<<message<<"\nSQLSTATE: "<<sqlstate<<endl;
}

int main(){
        SQLHANDLE sqlenvhandle;   
    SQLHANDLE sqlconnectionhandle;
    SQLHANDLE sqlstatementhandle;
    SQLRETURN retcode;

    if(SQL_SUCCESS!=SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &sqlenvhandle))
        goto FINISHED;

    if(SQL_SUCCESS!=SQLSetEnvAttr(sqlenvhandle,SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0))
        goto FINISHED;
   
    if(SQL_SUCCESS!=SQLAllocHandle(SQL_HANDLE_DBC, sqlenvhandle, &sqlconnectionhandle))
        goto FINISHED;

    SQLCHAR retconstring[1024];
    switch(SQLDriverConnect (sqlconnectionhandle,
                NULL,
                (SQLCHAR*)"DRIVER={SQL Server};SERVER=localhost, 1433;DATABASE=MyDatabase;UID=sa;PWD=Admin-123;",
                SQL_NTS,
                retconstring,
                1024,
                NULL,
                SQL_DRIVER_NOPROMPT)){
        case SQL_SUCCESS_WITH_INFO:
            show_error(SQL_HANDLE_DBC, sqlconnectionhandle);
            break;
        case SQL_INVALID_HANDLE:
        case SQL_ERROR:
            show_error(SQL_HANDLE_DBC, sqlconnectionhandle);
            goto FINISHED;
        default:
            break;
    }
   
    if(SQL_SUCCESS!=SQLAllocHandle(SQL_HANDLE_STMT, sqlconnectionhandle, &sqlstatementhandle))
        goto FINISHED;

    if(SQL_SUCCESS!=SQLExecDirect(sqlstatementhandle, (SQLCHAR*)"select * from testtable", SQL_NTS)){
        show_error(SQL_HANDLE_STMT, sqlstatementhandle);
        goto FINISHED;
    }
    else{
        char name[64];
        char address[64];
        int id;
        while(SQLFetch(sqlstatementhandle)==SQL_SUCCESS){
            SQLGetData(sqlstatementhandle, 1, SQL_C_ULONG, &id, 0, NULL);
            SQLGetData(sqlstatementhandle, 2, SQL_C_CHAR, name, 64, NULL);
            SQLGetData(sqlstatementhandle, 3, SQL_C_CHAR, address, 64, NULL);
            cout<<id<<" "<<name<<" "<<address<<endl;
        }
    }

FINISHED:
    SQLFreeHandle(SQL_HANDLE_STMT, sqlstatementhandle );
    SQLDisconnect(sqlconnectionhandle);
    SQLFreeHandle(SQL_HANDLE_DBC, sqlconnectionhandle);
    SQLFreeHandle(SQL_HANDLE_ENV, sqlenvhandle);
   
}


and here are the errors

code:
'TEST.exe': Loaded 'C:\Users\Shahab Tran\Documents\Visual Studio 2010\Projects\TEST\Debug\TEST.exe', Symbols loaded.
'TEST.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\odbc32.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\sechost.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\msvcp100d.dll', Symbols loaded.
'TEST.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
'TEST.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\odbcint.dll', Binary was not built with debug information.
'TEST.exe': Loaded 'C:\Windows\System32\bcrypt.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\bcryptprimitives.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\sqlsrv32.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\crypt32.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\msasn1.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\netapi32.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\netutils.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\srvcli.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\wkscli.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\version.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\sqlsrv32.rll', Binary was not built with debug information.
'TEST.exe': Loaded 'C:\Windows\System32\sspicli.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\odbccp32.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\cryptbase.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\dbnetlib.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\ws2_32.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\nsi.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\security.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\secur32.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\cryptsp.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\credssp.dll', Cannot find or open the PDB file
'TEST.exe': Unloaded 'C:\Windows\System32\cryptsp.dll'
'TEST.exe': Loaded 'C:\Windows\System32\msv1_0.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\cryptdll.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\ntdsapi.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\mswsock.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\WSHTCPIP.DLL', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\wship6.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\dnsapi.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Program Files\Common Files\microsoft shared\Windows Live\WLIDNSP.DLL', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\psapi.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\IPHLPAPI.DLL', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\winnsi.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\rasadhlp.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\FWPUCLNT.DLL', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\schannel.dll', Cannot find or open the PDB file
'TEST.exe': Loaded 'C:\Windows\System32\ncrypt.dll', Cannot find or open the PDB file
Run-Time Check Failure #3 - The variable 'sqlstatementhandle' is being used without being initialized.
First-chance exception at 0x6d8b96ec in TEST.exe: 0xC0000005: Access violation reading location 0xcccccccc.
Unhandled exception at 0x6d8b96ec in TEST.exe: 0xC0000005: Access violation reading location 0xcccccccc.
First-chance exception at 0x6d8b96ec in TEST.exe: 0xC0000005: Access violation reading location 0xcccccccc.
Unhandled exception at 0x6d8b96ec in TEST.exe: 0xC0000005: Access violation reading location 0xcccccccc.
First-chance exception at 0x6d8b96ec in TEST.exe: 0xC0000005: Access violation reading location 0xcccccccc.
Unhandled exception at 0x6d8b96ec in TEST.exe: 0xC0000005: Access violation reading location 0xcccccccc.
First-chance exception at 0x6d8b96ec in TEST.exe: 0xC0000005: Access violation reading location 0xcccccccc.
Unhandled exception at 0x6d8b96ec in TEST.exe: 0xC0000005: Access violation reading location 0xcccccccc.
First-chance exception at 0x6d8b96ec in TEST.exe: 0xC0000005: Access violation reading location 0xcccccccc.
Unhandled exception at 0x6d8b96ec in TEST.exe: 0xC0000005: Access violation reading location 0xcccccccc.
The program '[13340] TEST.exe: Native' has exited with code -1073741819 (0xc0000005).


if anyone could help me it would be much appreciated
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Thu Jul 28, 2011 5:10 pm   Post subject: RE:ODBC with C++ to SQL

The messages about PDBs missing are warnings, not errors. They're telling you that Visual Studio can't find debugger information for those dll files, so (among other things) you won't get to see variable names, method names, structure names, etc while debugging. It's not an error, and not unexpected.

The error is happening because the "sqlstatementhandle" variable is being accessed without being initialized. That probably means that the call to SQLAllocHandle failed, your program followed the "goto FINISHED" line, and is now trying to free a handle that was never allocated.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: