Re: SQL_ATTR_LOGIN_TIMEOUT behaviour

Nick Gorham <[email protected]> Tue, 22 Mar 2016 10:01:24 +0000
Newsgroups gmane.comp.db.unixodbc.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--===============0543062004==
Content-Type: multipart/alternative;
	boundary="------------060601080706090201090906"

This is a multi-part message in MIME format.
--------------060601080706090201090906
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 7bit

On 22/03/16 07:34, Satheesh Subramanian wrote:
> Hi,
>  We ran into a problem where connection to mysql database is not 
> timing out within specified SQL_ATTR_LOGIN_TIMEOUT value even when the 
> database is not reachable.
>
>  We use UNixODBC driver manager and mysql odbc driver to connect to 
> the mysql database. In order to make a connection to the database we 
> do the following
> 1) Allocate Handle
> 2) Set SQL_ATTR_LOGIN_TIMEOUT to 5 seconds by calling SQLSetConnectAttr
> 3) Call SQLDriverConnect to make the connection.
>
> To debug the issue, I first enabled the trace logs and then started to 
> look at the source code of unix odbc driver manager.

Well, checking here with the current build (and I dont see any changes 
that would affect this) __connect_part_one() contains

     /*
      * set any connection atributes
      */

     DO_ATTR( connection, access_mode, SQL_ATTR_ACCESS_MODE, 
SQL_ACCESS_MODE );
*    DO_ATTR( connection, login_timeout, SQL_ATTR_LOGIN_TIMEOUT, 
SQL_LOGIN_TIMEOUT );*
     DO_ATTR( connection, auto_commit, SQL_ATTR_AUTOCOMMIT, 
SQL_AUTOCOMMIT );
     DO_ATTR( connection, async_enable, SQL_ATTR_ASYNC_ENABLE, 
SQL_ASYNC_ENABLE );
     DO_ATTR( connection, auto_ipd, SQL_ATTR_AUTO_IPD, 0 );
     DO_ATTR( connection, connection_timeout, 
SQL_ATTR_CONNECTION_TIMEOUT, 0 );
     DO_ATTR( connection, metadata_id, SQL_ATTR_METADATA_ID, 0 );
     DO_ATTR( connection, packet_size, SQL_ATTR_PACKET_SIZE, 
SQL_PACKET_SIZE );
     DO_ATTR( connection, quite_mode, SQL_ATTR_QUIET_MODE, SQL_QUIET_MODE );
     DO_ATTR( connection, txn_isolation, SQL_ATTR_TXN_ISOLATION, 
SQL_TXN_ISOLATION );

And SQLSetConnectAttr.c contains

     /*
      * we need to save this even if connected so we can use it for the 
next connect
      */
     if ( attribute == SQL_ATTR_LOGIN_TIMEOUT )
     {
         connection -> login_timeout = ( SQLLEN ) value;
         connection -> login_timeout_set = 1;
     }

And the comment when this was changed

  * Revision 1.4  2002/01/10 11:17:20  lurcher
  *
  * Allow SQL_ATTR_LOGIN_TIMEOUT to be set when connected to mirror what the
  * MS DM does


2002 is release 2.2.0, so thats been there for some time.

I just tried with one of our (Easysoft) drivers to check, and it seems 
to work as I would expect, calling SQLSetConnect in the driver between 
the SQLAllocEnv( SQL_CONNECT ) and the SQLConnect/SQLDriverConnect

-- 
Nick

--------------060601080706090201090906
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mail.lurcher.org id u2MA14iM003193

<html>
  <head>
    <meta content=3D"text/html; charset=3Dwindows-1252"
      http-equiv=3D"Content-Type">
  </head>
  <body text=3D"#000000" bgcolor=3D"#FFFFFF">
    <div class=3D"moz-cite-prefix">On 22/03/16 07:34, Satheesh Subramania=
n
      wrote:<br>
    </div>
    <blockquote
cite=3D"mid:[email protected]=
l.com"
      type=3D"cite">
      <div dir=3D"ltr">Hi,
        <div>=A0We ran into a problem where connection to mysql=A0databas=
e
          is not timing out within specified SQL_ATTR_LOGIN_TIMEOUT
          value even when the database is not reachable.</div>
        <div><br>
        </div>
        <div>=A0We use UNixODBC driver manager and mysql odbc=A0driver to
          connect to the mysql database. In order to make a connection
          to the database we do the following</div>
        <div>1) Allocate Handle</div>
        <div>2) Set=A0SQL_ATTR_LOGIN_TIMEOUT to 5 seconds by calling
          SQLSetConnectAttr</div>
        <div>3) Call SQLDriverConnect to make the connection.</div>
        <div><br>
        </div>
        <div>To debug the issue, I first enabled the trace logs and then
          started to look at the source code of unix odbc driver
          manager.</div>
      </div>
    </blockquote>
    <br>
    Well, checking here with the current build (and I dont see any
    changes that would affect this) __connect_part_one() contains<br>
    <br>
    =A0=A0=A0 /*<br>
    =A0=A0=A0=A0 * set any connection atributes<br>
    =A0=A0=A0=A0 */<br>
    <br>
    =A0=A0=A0 DO_ATTR( connection, access_mode, SQL_ATTR_ACCESS_MODE,
    SQL_ACCESS_MODE );<br>
    <b>=A0=A0=A0 DO_ATTR( connection, login_timeout, SQL_ATTR_LOGIN_TIMEO=
UT,
      SQL_LOGIN_TIMEOUT );</b><br>
    =A0=A0=A0 DO_ATTR( connection, auto_commit, SQL_ATTR_AUTOCOMMIT,
    SQL_AUTOCOMMIT );<br>
    =A0=A0=A0 DO_ATTR( connection, async_enable, SQL_ATTR_ASYNC_ENABLE,
    SQL_ASYNC_ENABLE );<br>
    =A0=A0=A0 DO_ATTR( connection, auto_ipd, SQL_ATTR_AUTO_IPD, 0 );<br>
    =A0=A0=A0 DO_ATTR( connection, connection_timeout,
    SQL_ATTR_CONNECTION_TIMEOUT, 0 );<br>
    =A0=A0=A0 DO_ATTR( connection, metadata_id, SQL_ATTR_METADATA_ID, 0 )=
;<br>
    =A0=A0=A0 DO_ATTR( connection, packet_size, SQL_ATTR_PACKET_SIZE,
    SQL_PACKET_SIZE );<br>
    =A0=A0=A0 DO_ATTR( connection, quite_mode, SQL_ATTR_QUIET_MODE,
    SQL_QUIET_MODE );<br>
    =A0=A0=A0 DO_ATTR( connection, txn_isolation, SQL_ATTR_TXN_ISOLATION,
    SQL_TXN_ISOLATION );<br>
    <br>
    And SQLSetConnectAttr.c contains<br>
    <br>
    =A0=A0=A0 /*<br>
    =A0=A0=A0=A0 * we need to save this even if connected so we can use i=
t for
    the next connect<br>
    =A0=A0=A0=A0 */<br>
    =A0=A0=A0 if ( attribute =3D=3D SQL_ATTR_LOGIN_TIMEOUT )<br>
    =A0=A0=A0 {<br>
    =A0=A0=A0=A0=A0=A0=A0 connection -&gt; login_timeout =3D ( SQLLEN ) v=
alue;<br>
    =A0=A0=A0=A0=A0=A0=A0 connection -&gt; login_timeout_set =3D 1;<br>
    =A0=A0=A0 }<br>
    <br>
    And the comment when this was changed<br>
    <br>
    =A0* Revision 1.4=A0 2002/01/10 11:17:20=A0 lurcher<br>
    =A0*<br>
    =A0* Allow SQL_ATTR_LOGIN_TIMEOUT to be set when connected to mirror
    what the<br>
    =A0* MS DM does<br>
    <br>
    <br>
    2002 is release 2.2.0, so thats been there for some time.<br>
    <br>
    I just tried with one of our (Easysoft) drivers to check, and it
    seems to work as I would expect, calling SQLSetConnect in the driver
    between the SQLAllocEnv( SQL_CONNECT ) and the
    SQLConnect/SQLDriverConnect<br>
    <br>
    -- <br>
    Nick<br>
  </body>
</html>

--------------060601080706090201090906--

--===============0543062004==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Disposition: inline
Content-Transfer-Encoding: 7bit

_______________________________________________
unixODBC-dev mailing list
[email protected]
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev

--===============0543062004==--