Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
Subject: mysql openssl Question
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
Update one field with more fields from another table
Subject: Getting Identity after INSERT
ERROR 2002: Can 't connect to local MySQL server through socket
mysql test 4 1 fails with the gis test
Subject: MySQL Cluster Software
Downgrade Mysql from 4 to 3 23
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Can 't access mysql after kernel upgrade
Executing MySQL Commands From Within C Program
Comparing and writing out BLOBS
Subject: Re: Preventing Duplicate Entries
FULLTEXT query format question
Strange behavior, Table Level Permission
Does the binary log enabling affect the MySQL performances?
mysql:it 's a db not a dbms how it 's possible?!
mysql have same function mthod as Oracle decode()
 
Subject: reconnect failing in 3.51.12

Subject: reconnect failing in 3.51.12

2007-02-09       - By John Calcote

 Back
Reply:     1     2     3     4     5     6     7  

I've got a linux daemon that logs to myodbc 3.51.12 through unixODBC driver
manager. The first time my program receives a command it establishes an entire
ODBC environment via the following (abbreviated) code:

  int connect()
  {
     SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hsql);
     SQLSetEnvAttr(hsql, SQL_ATTR_ODBC_VERSION, (void *)SQL_OV_ODBC3, 0);
     SQLAllocHandle(SQL_HANDLE_DBC, hsql, &hdbc);
     SQLConnect(hdbc, (SQLCHAR*)dsn, SQL_NTS, (SQLCHAR*)user, SQL_NTS,
(SQLCHAR*)passwd, SQL_NTS);
     SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
     SQLPrepare(hstmt, primary_stmt, SQL_NTS);

     for (i = 0; i < elemcount(pa); i++)
        SQLBindParameter(hstmt, j++, SQL_PARAM_INPUT, pa[i].c_type, pa[i].s
_type, pa[i].csize, 0, pa[i].pvp, 0, &ind[i]);
  }

  void disconnect()
  {
     if (hstmt != 0)
        SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
     if (hdbc != 0)
     {
        SQLDisconnect(hdbc);
        SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
     }
     if (hsql != 0)
        SQLFreeHandle(SQL_HANDLE_ENV, hsql);
     hstmt = hdbc = hsql = 0;
  }
Of course, I check all of the error returns in the real code. The daemon
monitors for intermittent request traffic and logs things to the database as
requests come in. If there's an 8 hour delay between requests, the ODBC
connection times out. I expect this condition in the log code as follows:

  if (!SQL_SUCCEEDED(SQLExecute(hstmt)))
  {
     disconnect();
     if (connect() != 0)
        return -1;
     else if (!SQL_SUCCEEDED(SQLExecute(hstmt)))
        return -1;
  }
My problem is that I cannot re-establish the connection once it's been broken
like this. I get errors back from myodbc like this:

  (a snippet from my daemon's log file)
  [Wed Feb  7 15:26:32 2007] Entering main run loop...

  (first request established initial connection)
  [Wed Feb  7 15:27:48 2007] xdm_odbc: Connection established. [DSN=xdas;UID
=root;PWD=;].

  (second request - over 8 hours later - tries to re-establish connection)
  [Fri Feb  9 02:52:56 2007] xdm_odbc: the ODBC driver reported -1 during
SQLConnect:
  [Fri Feb  9 02:52:56 2007] xdm_odbc: HYT00:1:2019:[unixODBC][MySQL][ODBC 3
.51 Driver]Can't initialize character set latin1 (path: /usr/share/mysql
/charsets/)
  [Fri Feb  9 02:52:56 2007] xdm_odbc: ODBC Reconnect failed, error -1.
What am I doing wrong? It seems simple enough to me. I noticed on the mailing
list that a few folks had trouble using SQLDriverConnect, so I switched to
SQLConnect, and now I get other types of errors trying to reconnect - not the
least of these are that my daemon segfaults down inside of libmyodbc with the
following stack trace:

#0  0xb741dc5d in my_strcasecmp_8bit () from /usr/lib/mysql/libmysqlclient.so.15
#1  0xb741514d in get_charset_number () from /usr/lib/mysql/libmysqlclient.so.15
#2  0xb74151ab in get_charset_by_csname () from /usr/lib/mysql/libmysqlclient
.so.15
#3  0xb74320ec in mysql_real_connect () from /usr/lib/mysql/libmysqlclient.so.15
#4  0xb753c15a in SQLConnect (hdbc=0x807fe78, szDSN=0xb7d8df51, cbDSN=-3,
   szUID=0xb7d8e270, cbUID=-3, szAuthStr=0xb7d8e1f0, cbAuthStr=-3) at connect
.c:253
#5  0xb7d9d394 in SQLConnect (connection_handle=0x80616f0,
   server_name=0xb7d8e2f0, name_length1=-3, user_name=0xb7d8e270,
   name_length2=-3, authentication=0xb7d8e1f0, name_length3=-3) at SQLConnect
.c:3820
#6  0xb7f63c23 in sql_connect () at xdm_odbc.c:322
#7  0xb7f6411a in xdm_append (msg=0x80776a9, msgsz=272) at xdm_odbc.c:394
#8  0x0804a3cf in xdasd_logger_append (msg=0x8077598, msgsz=272) at xdasd
_logger.c:175
#9  0x0804a0e2 in bg_logger (unused=0x0) at xdasd_lcache.c:90
#10 0xb7f3b34b in start_thread () from /lib/libpthread.so.0
#11 0xb7ed365e in clone () from /lib/libc.so.6
Any ideas would be appreciated.

Thanks,
John


-- --
John Calcote (jcalcote@(protected))
Sr. Software Engineeer
Novell, Inc.

<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859 (See http://iso-8859.ora-code.com)-15">
<META content="MSHTML 6.00.5730.11" name=GENERATOR></HEAD>
<BODY style="MARGIN: 4px 4px 1px; FONT: 10pt Tahoma">
<DIV>I've got a linux daemon that logs to myodbc 3.51.12 through unixODBC
driver manager. The first time my program receives a command it establishes an
entire ODBC environment via the following (abbreviated)&nbsp;code:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp; int connect()</DIV>
<DIV>&nbsp;&nbsp; {</DIV>
<DIV>&nbsp;&nbsp; &nbsp;&nbsp; SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE,
&amp;hsql);</DIV>
<DIV>&nbsp;&nbsp; &nbsp;&nbsp; SQLSetEnvAttr(hsql, SQL_ATTR_ODBC_VERSION, (void
*)SQL_OV_ODBC3, 0);</DIV>
<DIV>&nbsp;&nbsp; &nbsp;&nbsp; SQLAllocHandle(SQL_HANDLE_DBC, hsql, &amp;hdbc);
</DIV>
<DIV>&nbsp;&nbsp; &nbsp;&nbsp; SQLConnect(hdbc, (SQLCHAR*)dsn, SQL_NTS,&nbsp;
(SQLCHAR*)user, SQL_NTS, (SQLCHAR*)passwd, SQL_NTS);</DIV>
<DIV>&nbsp;&nbsp; &nbsp;&nbsp; SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &amp;hstmt
);</DIV>
<DIV>&nbsp;&nbsp; &nbsp;&nbsp; SQLPrepare(hstmt, primary_stmt, SQL_NTS);</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp; &nbsp;&nbsp; for (i = 0; i &lt; elemcount(pa); i++)</DIV>
<DIV>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; SQLBindParameter(hstmt, j++, SQL
_PARAM_INPUT,&nbsp;pa[i].c_type, pa[i].s_type, pa[i].csize, 0, pa[i].pvp, 0,
&amp;ind[i]);</DIV>
<DIV>&nbsp;&nbsp; }</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp; void disconnect()<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp; &nbsp;
&nbsp; if (hstmt != 0)<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);<BR>&nbsp;&nbsp; &nbsp;&nbsp; if (hdbc !=
0)<BR>&nbsp;&nbsp; &nbsp;&nbsp; {<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp
; SQLDisconnect(hdbc);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);<BR>&nbsp;&nbsp; &nbsp;&nbsp; }<BR>&nbsp;
&nbsp; &nbsp;&nbsp; if (hsql != 0)<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp
; SQLFreeHandle(SQL_HANDLE_ENV, hsql);<BR>&nbsp;&nbsp; &nbsp;&nbsp; hstmt = hdbc
= hsql = 0;<BR>&nbsp;&nbsp; }<BR></DIV>
<DIV>Of course, I check all of the error returns in the real code. The daemon
monitors for intermittent request traffic and logs things to the database as
requests come in. If there's an 8 hour delay between requests, the ODBC
connection times out. I expect this condition in the log code as follows:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp; if (!SQL_SUCCEEDED(SQLExecute(hstmt)))<BR>&nbsp;&nbsp; {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; disconnect();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if (connect() != 0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return
-1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if (!SQL_SUCCEEDED(SQLExecute(hstmt))
)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return -1;<BR>&nbsp;
&nbsp; }<BR></DIV>
<DIV>My problem is that I cannot re-establish the connection once it's been
broken like this. I get errors back from myodbc like this:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp; (a snippet from my daemon's log file)</DIV>
<DIV>&nbsp;&nbsp; [Wed Feb&nbsp; 7 15:26:32 2007] Entering main run loop...<
/DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;(first&nbsp;request established initial connection)<BR>
&nbsp;&nbsp; [Wed Feb&nbsp; 7 15:27:48 2007] xdm_odbc: Connection established.
[DSN=xdas;UID=root;PWD=;].</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp; (second request&nbsp;-&nbsp;over 8 hours later - tries to re
-establish connection)<BR>&nbsp;&nbsp; [Fri Feb&nbsp; 9 02:52:56 2007] xdm_odbc:
the ODBC driver reported -1 during SQLConnect:<BR>&nbsp;&nbsp; [Fri Feb&nbsp; 9
02:52:56 2007] xdm_odbc: HYT00:1:2019:[unixODBC][MySQL][ODBC 3.51 Driver]Can't
initialize character set latin1 (path: /usr/share/mysql/charsets/)<BR>&nbsp;
&nbsp; [Fri Feb&nbsp; 9 02:52:56 2007] xdm_odbc: ODBC Reconnect failed, error -1
.<BR></DIV>
<DIV>What am I doing wrong? It seems simple enough to me. I noticed on the
mailing list that a few folks had trouble using SQLDriverConnect, so I switched
to SQLConnect, and now I get other types of errors trying to reconnect - not
the least of these are that my daemon segfaults down inside of libmyodbc with
the following stack trace:</DIV>
<DIV>&nbsp;</DIV>
<DIV>#0&nbsp; 0xb741dc5d in my_strcasecmp_8bit () from /usr/lib/mysql
/libmysqlclient.so.15<BR>#1&nbsp; 0xb741514d in get_charset_number () from /usr
/lib/mysql/libmysqlclient.so.15<BR>#2&nbsp; 0xb74151ab in get_charset_by_csname
() from /usr/lib/mysql/libmysqlclient.so.15<BR>#3&nbsp; 0xb74320ec in mysql_real
_connect () from /usr/lib/mysql/libmysqlclient.so.15<BR>#4&nbsp; 0xb753c15a in
SQLConnect (hdbc=0x807fe78, szDSN=0xb7d8df51, cbDSN=-3,<BR>&nbsp;&nbsp;&nbsp;
szUID=0xb7d8e270, cbUID=-3, szAuthStr=0xb7d8e1f0, cbAuthStr=-3) at connect.c
:253<BR>#5&nbsp; 0xb7d9d394 in SQLConnect (connection_handle=0x80616f0,<BR>&nbsp
;&nbsp;&nbsp; server_name=0xb7d8e2f0, name_length1=-3, user_name=0xb7d8e270,<BR>
&nbsp;&nbsp;&nbsp; name_length2=-3, authentication=0xb7d8e1f0, name_length3=-3)
at SQLConnect.c:3820<BR>#6&nbsp; 0xb7f63c23 in sql_connect () at xdm_odbc.c:322
<BR>#7&nbsp; 0xb7f6411a in xdm_append (msg=0x80776a9, msgsz=272) at xdm_odbc.c
:394<BR>#8&nbsp; 0x0804a3cf in xdasd_logger_append (msg=0x8077598, msgsz=272) at
xdasd_logger.c:175<BR>#9&nbsp; 0x0804a0e2 in bg_logger (unused=0x0) at xdasd
_lcache.c:90<BR>#10 0xb7f3b34b in start_thread () from /lib/libpthread.so.0<BR>
#11 0xb7ed365e in clone () from /lib/libc.so.6<BR></DIV>
<DIV>Any ideas would be appreciated.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks,</DIV>
<DIV>John</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>-- --<BR>John Calcote (jcalcote@(protected))<BR>Sr. Software
Engineeer<BR>Novell, Inc.<BR></BODY></HTML>


--
MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe:    http://lists.mysql.com/myodbc?unsub=mysql@(protected)