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 |