mysql_real_connect() breaks in libmysqld trying to access a distant server

mysql_real_connect() breaks in libmysqld trying to access a distant server

am 31.03.2005 22:19:38 von jpleveille

Hi,

Message may be long, but in short I encountered an issue that may be a =
bug or something I did wrong. It appears that the call to
mysql_real_connect() to connect to a distant server with libmysqld (the =
embedded server) doesn't work, resulting in an access
violation.

I've wanted to embed the MySQL server into my application built with the =
Microsoft Development Environment 2003 (Visual C++) and it
worked very fine. libmysqld works well with it to use with a database =
embedded on the computer where the application is running.

MySQL Documentation tells that it is still possible "to connect to an =
external server without starting the embedded server", by
specifying a negative value for argc in mysql_server_init() (or =
mysql_library_init()). Considering that, it would be transparent for
me to either use libmysql or libmysqld to connect to a distant server =
and this way I won't have to deliver two versions of my
application, one for distant server access and the other for local =
server access (do not read "localhost").
Ref: http://dev.mysql.com/doc/mysql/en/mysql-server-init.html

Problem is: using a different DLL (libmysql) instead of the embedded =
server (libmysqld), I can easily connect to a distant server,
but I can't with libmysqld, it just breaks when I call =
mysql_real_connect(). It returns me a message like:

First-chance exception at 0x7c918fea in testmysql.exe: 0xC0000005: =
Access violation writing location 0x00000010.
Unhandled exception at 0x7c918fea in testmysql.exe: 0xC0000005: Access =
violation writing location 0x00000010.
The program '[536] testmysql.exe: Native' has exited with code 0 (0x0).

Addresses look weird, seems unaligned to me... :?

For me, I thought the only difference between an application linked with =
libmysqld and libmysql is that the first is capable of
being a server as well as a client (libmysqld) and the second is purely =
a client (libmysql). Am I right on this? Or is my DLL wrong?

I'm using the embedded version libmysqld in MySQL 4.1.10a, I've tried =
both debug and release DLLs and both are returning the same
error, without any message.

Tell me if I'm wrong posting this message here. I didn't want to post a =
new bug entry because I'm quite a newbie at embedding DLLs
in C++ applications and I may have missed something. :)

Code sample:

int server_argc =3D -1; // negative number, to contact an external =
server
mysql_library_init(server_argc, NULL, NULL);
....
MYSQL *db =3D mysql_init(NULL);
if (!db)
{
die(db, "mysql_init() failed");
}

// libmysqld =3D> hangs totally if mysql_library_init() is called with =
argc < 0
// to call an external server -> using it same as if =
libmysql was
// loaded
// libmysql =3D> works fine
if (!mysql_real_connect(db, hostname, username, password, dbname, 3306, =
NULL, 0))
{
die(db, "mysql_real_connect failed: %s", mysql_error(db));
}

====================
Jean-Philippe L=E9veill=E9
Programmer
Unima Logiciel Inc.
jpleveille@unimasoft.com
http://www.unimasoft.com


--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=3Dgcdmw-win32@m.gmane.org