SQL+ Visual C++

Hi, i'm having major problems trying to get VC++ 2010 working with SQL Server 2008 and even MySQL

I've ran through a few tutorials on setting it up and they are all giving me simular errors.

i have just ran through the tutorial on http://www.cprogramming.com/tutorial/intro_to_ado_in_c++.html

anyone experienced this before?
i'm only wanting to learn a few bits about SQL with c++, this has turned into a waste of 2 days and a complete nightmare.


any insight on what the problem is would be great.

the error code i'm getting is:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'sql.exe': Loaded 'C:\Users\Carl\Documents\Visual Studio 2010\Projects\sql attempt2\Debug\sql.exe', Symbols loaded.
'sql.exe': Loaded 'C:\Windows\System32\ntdll.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\kernel32.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\ole32.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\gdi32.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\user32.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\advapi32.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
'sql.exe': Loaded 'C:\Windows\System32\shimeng.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\apphelp.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\imm32.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\msctf.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\lpk.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\usp10.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Program Files\SearchCore for Browsers\SearchCore for Browsers\datamngr.dll', Cannot find or open the PDB file
'sql.exe': Loaded 'C:\Windows\System32\wtsapi32.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\dbghelp.dll', Symbols loaded (source information stripped).
'sql.exe': Unloaded 'C:\Program Files\SearchCore for Browsers\SearchCore for Browsers\datamngr.dll'
'sql.exe': Unloaded 'C:\Windows\System32\dbghelp.dll'
'sql.exe': Unloaded 'C:\Windows\System32\wtsapi32.dll'
'sql.exe': Loaded 'C:\Program Files\SearchCore for Browsers\SearchCore for Browsers\IEBHO.dll', Cannot find or open the PDB file
'sql.exe': Loaded 'C:\Windows\System32\dbghelp.dll', Symbols loaded (source information stripped).
'sql.exe': Unloaded 'C:\Program Files\SearchCore for Browsers\SearchCore for Browsers\IEBHO.dll'
'sql.exe': Unloaded 'C:\Windows\System32\dbghelp.dll'
'sql.exe': Loaded 'C:\Program Files\Kaspersky Lab\Kaspersky Internet Security 2011\kloehk.dll', Cannot find or open the PDB file
'sql.exe': Loaded 'C:\Windows\System32\psapi.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.4053_none_d08d7da0442a985d\msvcr80.dll', Symbols loaded.
'sql.exe': Unloaded 'C:\Program Files\Kaspersky Lab\Kaspersky Internet Security 2011\kloehk.dll'
'sql.exe': Unloaded 'C:\Windows\winsxs\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.4053_none_d08d7da0442a985d\msvcr80.dll'
'sql.exe': Unloaded 'C:\Windows\System32\psapi.dll'
'sql.exe': Unloaded 'C:\Windows\System32\shimeng.dll'
'sql.exe': Unloaded 'C:\Windows\System32\apphelp.dll'
'sql.exe': Loaded 'C:\Windows\System32\uxtheme.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\clbcatq.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Program Files\Common Files\System\ado\msado15.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\msdart.dll', Symbols loaded (source information stripped).
'sql.exe': Loaded 'C:\Windows\System32\rsaenh.dll', Symbols loaded (source information stripped).
'sql.exe': Unloaded 'C:\Program Files\Common Files\System\ado\msado15.dll'
'sql.exe': Unloaded 'C:\Windows\System32\msdart.dll'
First-chance exception at 0x01002165 in sql.exe: 0xC0000005: Access violation reading location 0x00f91370.
Unhandled exception at 0x01002165 in sql.exe: 0xC0000005: Access violation reading location 0x00f91370.
The program '[2948] sql.exe: Native' has exited with code 0 (0x0).

closed account (3hM2Nwbp)
Since you're using Microsoft's VC++ IDE, you can navigate through the stack trace quite easily. What you've got there looks like memory corruption. (IE calling delete twice / dereferencing a null pointer) Can you post the code you're running?
I'm working my way through it, i used a file that sombody provided to include all the #includes and apparently it hasnt added any of them. Hoping thats going to work doing it manually.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdlib.h>
#include <iostream>

#include <driver.h>
#include <exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>

int main(){

    sql::Driver *driver;
    sql::Connection *con;
    sql::Statement *stmt;
    sql::ResultSet *res;
    sql::PreparedStatement *pstmt;
    
    try{
        driver = get_driver_instance();
        con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
        con->setSchema("test");
        
        stmt = con->createStatement();
        stmt->execute("insert into example values(4,'four'),(5, 'five')");
        delete stmt;

        pstmt = con->prepareStatement("select * from example");
        res = pstmt->executeQuery();
        while (res->next())
            std::cout<<res->getInt("id")<<"  "<<res->getString("data")<<std::endl;
        delete res;
        delete pstmt;

        pstmt = con->prepareStatement("delete from example where id=?");
        pstmt->setInt(1,4);
        pstmt->executeUpdate();
        pstmt->setInt(1,5);
        pstmt->executeUpdate();

        delete pstmt;

        delete con;    
    }catch(sql::SQLException &e){
        std::cout<<e.what();
    }
}
closed account (3hM2Nwbp)
I had similar issues when using the official mysql c++ API, another thing that you need to make sure of is that the version of the headers you're using matches the version of the library files.

It is also a factor whether you're linking statically or dynamically. I recall that if you try to link statically, then a certain preprocessor token must be defined. I'll search for that and post back if I can find it.
closed account (3hM2Nwbp)
cppconn Documentation wrote:
By default CPPCONN_PUBLIC_FUNC is defined to declare functions to be compatible with an application that calls a DLL. If building an application to call the static library, you must ensure that function prototypes are compatible with this. In this case CPPCONN_PUBLIC_FUNC needs to be defined to be an empty string, so that functions are declared with the correct prototype.
Hm, what is a good substitute for SQL?

It's completely confused me, to many versions and too many different compilers, its hard to find the right advice for my particular circumstances.
closed account (3hM2Nwbp)
You may consider trying the MSI installer to simplify things.

http://www.mysql.com/downloads/mirror.php?id=393849#mirrors

Trust me, it's confusing at first, but after a month or so, you'll be able to link in libraries much easier. That installer should create a directory and put a set of folders inside: include and lib. Point your IDE toward these directories and see how it works for you.
do i need to link the lib files and the include files?
closed account (3hM2Nwbp)
In Visual Studio you will need to specify the library directories and include directories. This is done in your project properties. You will also need to add in the name of the library to link to (mysqlcppconn.lib). I'll be uploading some images to help you shortly.

Setting Include Directory:
http://img6.imageshack.us/img6/6625/include.png

Setting Library Directory:
http://img717.imageshack.us/img717/8586/includey.png

Setting Library Dependency:
http://img15.imageshack.us/img15/6625/include.png
Last edited on
just a lil walk through of what i'm doing,

in the directories for include i've put
C:\Program Files\MySQL\Connector C++ 1.1.0\include

directories for library I've put
C:\Program Files\MySQL\Connector C++ 1.1.0\lib

debug and run codes up with the following errors:
1
2
3
1
1>  test.cpp
1>c:\program files\mysql\connector c++ 1.1.0\include\cppconn\connection.h(29): fatal error C1083: Cannot open include file: 'boost/variant.hpp': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


so i d/led the zip file of boosts (90mb+ one)

add them to include directory and lib directory just incase
C:\Users\.....\boost_1_47_0

now the error i'm getting after that is
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
1>  test.cpp
1>c:\program files\mysql\connector c++ 1.1.0\include\cppconn\sqlstring.h(36): warning C4251: 'sql::SQLString::realStr' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'sql::SQLString'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Ax=std::allocator<char>
1>          ]
1>c:\program files\mysql\connector c++ 1.1.0\include\cppconn\exception.h(59): warning C4251: 'sql::SQLException::sql_state' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'sql::SQLException'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Ax=std::allocator<char>
1>          ]
1>c:\program files\mysql\connector c++ 1.1.0\include\cppconn\config.h(60): error C2371: 'int8_t' : redefinition; different basic types
1>          c:\program files\microsoft visual studio 10.0\vc\include\stdint.h(17) : see declaration of 'int8_t'
1>c:\program files\mysql\connector c++ 1.1.0\include\cppconn\config.h(60): error C2371: 'int8_t' : redefinition; different basic types
1>          c:\program files\microsoft visual studio 10.0\vc\include\stdint.h(17) : see declaration of 'int8_t'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


i have no clue what the problem is cos I've never done any SQL before. I'm gueseing with the code coming from a tutorial though, its more than likely right. I don't it was written for an up to date version of SQL tho.

anyway if you can make heads or tails over it, your my hero :p
Last edited on
closed account (3hM2Nwbp)
The "Official" connector API is quite poorly packaged IMO. You're encountering all of the issues that I have when I first started working with it. I expect that the library creators never decided thoroughly test it.

So now you have an error on line 60 of config.h of the connector API. It's saying that int8_t is already defined, which it is in stdint.h

To resolve this, you can try commenting out the definition of int8_t in config.h

Here's what I had to do to the config.h file to get it to work on my system:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
   Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.

   The MySQL Connector/C++ is licensed under the terms of the GPL
   <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
   MySQL Connectors. There are special exceptions to the terms and
   conditions of the GPL as it is applied to this software, see the
   FLOSS License Exception
   <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
*/

// libmysql defines HAVE_STRTOUL (on win), so we have to follow different pattern in definitions names
// to avoid annoying warnings.

/* #undef HAVE_FUNCTION_STRTOLD */
/* #undef HAVE_FUNCTION_STRTOLL */
#define HAVE_FUNCTION_STRTOL 1
/* #undef HAVE_FUNCTION_STRTOULL */

#define HAVE_FUNCTION_STRTOUL 1

/* #undef HAVE_FUNCTION_STRTOIMAX */
/* #undef HAVE_FUNCTION_STRTOUMAX */

/* #undef HAVE_STDINT_H */
/* #undef HAVE_INTTYPES_H */

/* #undef HAVE_INT8_T */
/* #undef HAVE_UINT8_T */
/* #undef HAVE_INT16_T */
/* #undef HAVE_UINT16_T */
/* #undef HAVE_INT32_T */
/* #undef HAVE_UINT32_T */
/* #undef HAVE_INT32_T */
/* #undef HAVE_UINT32_T */
/* #undef HAVE_INT64_T */
/* #undef HAVE_UINT64_T */
#define HAVE_MS_INT8     1
#define HAVE_MS_UINT8    1
#define HAVE_MS_INT16    1
#define HAVE_MS_UINT16   1
#define HAVE_MS_INT32    1
#define HAVE_MS_UINT32   1
#define HAVE_MS_INT64   1
#define HAVE_MS_UINT64   1


#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include <stdint.h>
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif

/*#if defined(_WIN32)
#ifndef CPPCONN_DONT_TYPEDEF_MS_TYPES_TO_C99_TYPES

#if !defined(HAVE_INT8_T) && defined(HAVE_MS_INT8)
typedef __int8			int8_t;
#endif

#ifdef HAVE_MS_UINT8
typedef unsigned __int8	uint8_t;
#endif
#ifdef HAVE_MS_INT16
typedef __int16			int16_t;
#endif

#ifdef HAVE_MS_UINT16
typedef unsigned __int16	uint16_t;
#endif

#ifdef HAVE_MS_INT32
typedef __int32			int32_t;
#endif

#ifdef HAVE_MS_UINT32
typedef unsigned __int32	uint32_t;
#endif

#ifdef HAVE_MS_INT64
typedef __int64			int64_t;
#endif
#ifdef HAVE_MS_UINT64
typedef unsigned __int64	uint64_t;
#endif

#endif	// CPPCONN_DONT_TYPEDEF_MS_TYPES_TO_C99_TYPES
#endif	//	_WIN32
*/


PS. If you want a perfect boost installation, don't try to build it from source, it's an unwieldy monster. Check this site out for a boost installation procedure that actually works: http://www.boostpro.com/download/
Last edited on
OK yep that did something

changed my config.h

however error after error it would seem.
Also what do you mean by building from source, a lot of new terms been thrown out at once :p?

error is
LINK : fatal error LNK1104: cannot open file 'mysqlcppconn.lib'

I'll try fixing this one myself though. i hope
k just for reference if neone else has the same problem,

add
C:\Program Files\MySQL\Connector C++ 1.1.0\lib\opt

to library directories.
Topic archived. No new replies allowed.