Re: unixODBC-dev Digest, Vol 104, Issue 6
Satheesh Subramanian <[email protected]> Tue, 22 Mar 2016 09:00:14 -0700
| Newsgroups | gmane.comp.db.unixodbc.devel |
|---|---|
| Message-ID | <CALSGBWX9TGgb1rrHX52=-_Le8Donaz9Pkwwx6+KrU_LT4P8SMg@mail.gmail.com> |
--===============1440114994==
Content-Type: multipart/alternative; boundary=001a1143614a0f9ea3052ea54f4e
--001a1143614a0f9ea3052ea54f4e
Content-Type: text/plain; charset=UTF-8
Hey Nick,
Thanks a lot for looking into it.
We are using the unicode driver. do_attr method of the version which I was
using(2.3.1) was not setting the connect attribute to the unicode driver
static void do_attr( DMHDBC connection, int value,
int value_set, int attr3, int attr2 )
{
if ( value_set )
{
if (CHECK_SQLSETCONNECTATTR( connection ))
{
SQLSETCONNECTATTR(connection,
connection -> driver_dbc,
attr3,
value,
sizeof( value ));
}
else if (CHECK_SQLSETCONNECTOPTION(connection) && attr2 )
{
SQLSETCONNECTOPTION(connection,
connection -> driver_dbc,
attr2,
value );
}
}
}
But when I looked at the latest version of the code (2.3.4), it is indeed
setting the value to the unicode driver
static void do_attr( DMHDBC connection, int value,
int value_set, int attr3, int attr2 )
{
if ( value_set )
{
if (CHECK_SQLSETCONNECTATTR( connection ))
{
SQLSETCONNECTATTR(connection,
connection -> driver_dbc,
attr3,
value,
sizeof( value ));
}
else if (CHECK_SQLSETCONNECTOPTION(connection) && attr2 )
{
SQLSETCONNECTOPTION(connection,
connection -> driver_dbc,
attr2,
value );
}
else if (CHECK_SQLSETCONNECTATTRW( connection )) /* they are
int values, so this should be safe */
{
SQLSETCONNECTATTRW(connection,
connection -> driver_dbc,
attr3,
value,
sizeof( value ));
}
else if (CHECK_SQLSETCONNECTOPTIONW(connection) && attr2 )
{
SQLSETCONNECTOPTIONW(connection,
connection -> driver_dbc,
attr2,
value );
}
}
}
I have built the new version of the driver and it worked.
Thanks a lot for your help
On Tue, Mar 22, 2016 at 5:00 AM, <[email protected]>
wrote:
> Send unixODBC-dev mailing list submissions to
> [email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev
> or, via email, send a message with subject or body 'help' to
> [email protected]
>
> You can reach the person managing the list at
> [email protected]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of unixODBC-dev digest..."
>
>
> Today's Topics:
>
> 1. SQL_ATTR_LOGIN_TIMEOUT behaviour (Satheesh Subramanian)
> 2. Re: SQL_ATTR_LOGIN_TIMEOUT behaviour (Satheesh Subramanian)
> 3. Re: SQL_ATTR_LOGIN_TIMEOUT behaviour (Nick Gorham)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 22 Mar 2016 00:34:09 -0700
> From: Satheesh Subramanian <[email protected]>
> Subject: [unixODBC-dev] SQL_ATTR_LOGIN_TIMEOUT behaviour
> To: [email protected]
> Message-ID:
> <
> CALSGBWW4VmhY+8OA_TcHdnnKWWQDGdE9eeQ9qu6wajNtwNn9tQ@mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> 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.
>
> By looking at the SQLDriverConnectW.c code, looks like the
> attribute SQL_ATTR_LOGIN_TIMEOUT is only saved to an internal variable as
> long as the connection state is C2.
>
> And SQLDriverConnectW.c is trying to load the driver as part pf
> "part_one_connection" and then trying to make SQLDriverConnectW call to the
> mysql odbc driver. So, looks like SQL_ATTR_LOGIN_TIMEOUT is being ignored
> and will never be passed on to mysql driver unless the connection state is
> something other than C2. Looking at the code connection state would be
> moved out of S2 state only after a successful connect request to the driver
>
> I believe this is the reason why login timeout is not getting honoured.
>
> So, to confirm that, I made a change in SQLDriverConnectW to call the mysql
> driver to set the login timeout(which was saved to internal variable in an
> earlier call) after loading the driver but before making the actual
> connection. Afer this change, value set for SQL_ATTR_LOGIN_TIMEOUT started
> to work.
>
> I am not convinced driver manager would ignore the timeout and I suspect I
> am doing something wrong. I could not find the reason after going through
> the code multiple times over last few days.
>
> Can someone please point me to the right direction? How does the driver
> manager set the connection timeout to mysql driver? Any help is much
> appreciated!.
>
> Thanks in advance
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/20160322/0b6b7e28/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 2
> Date: Tue, 22 Mar 2016 01:12:21 -0700
> From: Satheesh Subramanian <[email protected]>
> Subject: Re: [unixODBC-dev] SQL_ATTR_LOGIN_TIMEOUT behaviour
> To: [email protected]
> Message-ID:
> <
> CALSGBWXwrbEkYfoDQDURFvYu3S1pKK6YkdGWAW5mSHCpNispsw@mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Please note we are using
> unixODBC version : 2.3.1
> mysql odbc driver version : 5.3.4
>
> On Tue, Mar 22, 2016 at 12:34 AM, Satheesh Subramanian <
> [email protected]> 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.
> >
> > By looking at the SQLDriverConnectW.c code, looks like the
> > attribute SQL_ATTR_LOGIN_TIMEOUT is only saved to an internal variable as
> > long as the connection state is C2.
> >
> > And SQLDriverConnectW.c is trying to load the driver as part pf
> > "part_one_connection" and then trying to make SQLDriverConnectW call to
> the
> > mysql odbc driver. So, looks like SQL_ATTR_LOGIN_TIMEOUT is being ignored
> > and will never be passed on to mysql driver unless the connection state
> is
> > something other than C2. Looking at the code connection state would be
> > moved out of S2 state only after a successful connect request to the
> driver
> >
> > I believe this is the reason why login timeout is not getting honoured.
> >
> > So, to confirm that, I made a change in SQLDriverConnectW to call the
> > mysql driver to set the login timeout(which was saved to internal
> variable
> > in an earlier call) after loading the driver but before making the
> actual
> > connection. Afer this change, value set for SQL_ATTR_LOGIN_TIMEOUT
> started
> > to work.
> >
> > I am not convinced driver manager would ignore the timeout and I suspect
> I
> > am doing something wrong. I could not find the reason after going through
> > the code multiple times over last few days.
> >
> > Can someone please point me to the right direction? How does the driver
> > manager set the connection timeout to mysql driver? Any help is much
> > appreciated!.
> >
> > Thanks in advance
> >
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/20160322/94ebbdad/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 3
> Date: Tue, 22 Mar 2016 10:01:24 +0000
> From: Nick Gorham <[email protected]>
> Subject: Re: [unixODBC-dev] SQL_ATTR_LOGIN_TIMEOUT behaviour
> To: [email protected]
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset="windows-1252"; Format="flowed"
>
> 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
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/20160322/7fd504f7/attachment-0001.html
> >
>
> ------------------------------
>
> _______________________________________________
> unixODBC-dev mailing list
> [email protected]
> http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev
>
>
> End of unixODBC-dev Digest, Vol 104, Issue 6
> ********************************************
>
--001a1143614a0f9ea3052ea54f4e
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hey Nick,=C2=A0<div>=C2=A0Thanks a lot for looking into it=
.</div><div><br></div><div>=C2=A0We are using the unicode driver. do_attr m=
ethod of the version which I was using(2.3.1) was not setting the connect a=
ttribute to the unicode driver</div><div><br></div><div><div>static void do=
_attr( DMHDBC connection, int value,</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
int value_set, int attr3, int attr2 =C2=A0)</div><div>{</div><div>=C2=A0 =
=C2=A0 if ( value_set )</div><div>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 if (CHECK_SQLSETCONNECTATTR( connection ))</div><div>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
SQLSETCONNECTATTR(connection,</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 connection -> driver_db=
c,</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 attr3,</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 value,</div><div>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 sizeof( value ));</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 }</div><div>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 else if (CHECK_SQLSETCONNECTOPTION(connection) &am=
p;& attr2 )</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 {</div><div>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 SQLSETCONNECTOPTION(connection,</div><di=
v>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 connection -> driver_dbc,</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 attr2,</div><di=
v>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 value );</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 }</div><div>=C2=
=A0 =C2=A0 }</div><div>}</div></div><div><br></div><div>But when I looked a=
t the latest version of the code (2.3.4), it is indeed setting the value to=
the unicode driver</div><div><br></div><div><div>static void do_attr( DMHD=
BC connection, int value,</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 int value_s=
et, int attr3, int attr2 =C2=A0)</div><div>{</div><div>=C2=A0 =C2=A0 if ( v=
alue_set )</div><div>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
if (CHECK_SQLSETCONNECTATTR( connection ))</div><div>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 SQLSETCONNECTA=
TTR(connection,</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 connection -> driver_dbc,</div><div>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 attr3,</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 value,</div><div>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 sizeof( =
value ));</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 else if (CHECK_SQLSETCONNECTOPTION(connection) && att=
r2 )</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 SQLSETCONNECTOPTION(connection,</div><div>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 c=
onnection -> driver_dbc,</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 attr2,</div><div>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 value );</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 else if (CHECK_SQLSETCONNECTATTRW( connection )) =C2=A0 =
=C2=A0 /* they are int values, so this should be safe */</div><div>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
SQLSETCONNECTATTRW(connection,</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 connection -> driver_d=
bc,</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 attr3,</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 value,</div><div>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 sizeof( value ));</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 }</div><div>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 else if (CHECK_SQLSETCONNECTOPTIONW(connection)=
&& attr2 )</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 {</div><div>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 SQLSETCONNECTOPTIONW(connection,</di=
v><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 connection -> driver_dbc,</div><div>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 attr2,</=
div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 value );</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 }</div><di=
v>=C2=A0 =C2=A0 }</div><div>}</div></div><div><br></div><div>I have built t=
he new version of the driver and it worked.=C2=A0</div><div><br></div><div>=
Thanks a lot for =C2=A0your help</div></div><div class=3D"gmail_extra"><br>=
<div class=3D"gmail_quote">On Tue, Mar 22, 2016 at 5:00 AM, <span dir=3D"l=
tr"><<a href=3D"mailto:[email protected]" target=
=3D"_blank">[email protected]</a>></span> wrote:=
<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-lef=
t:1px #ccc solid;padding-left:1ex">Send unixODBC-dev mailing list submissio=
ns to<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <a href=3D"mailto:[email protected]=
.org">[email protected]</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <a href=3D"http://mailman.unixodbc.org/mailman/=
listinfo/unixodbc-dev" rel=3D"noreferrer" target=3D"_blank">http://mailman.=
unixodbc.org/mailman/listinfo/unixodbc-dev</a><br>
or, via email, send a message with subject or body 'help' to<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <a href=3D"mailto:unixodbc-dev-request@mailman.=
unixodbc.org">[email protected]</a><br>
<br>
You can reach the person managing the list at<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <a href=3D"mailto:[email protected]=
ixodbc.org">[email protected]</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of unixODBC-dev digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
=C2=A0 =C2=A01. SQL_ATTR_LOGIN_TIMEOUT behaviour (Satheesh Subramanian)<br>
=C2=A0 =C2=A02. Re: SQL_ATTR_LOGIN_TIMEOUT behaviour (Satheesh Subramanian)=
<br>
=C2=A0 =C2=A03. Re: SQL_ATTR_LOGIN_TIMEOUT behaviour (Nick Gorham)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Tue, 22 Mar 2016 00:34:09 -0700<br>
From: Satheesh Subramanian <<a href=3D"mailto:[email protected]">sat=
[email protected]</a>><br>
Subject: [unixODBC-dev] SQL_ATTR_LOGIN_TIMEOUT behaviour<br>
To: <a href=3D"mailto:[email protected]">unixodbc-dev@mailm=
an.unixodbc.org</a><br>
Message-ID:<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <<a href=3D"mailto:CALSGBWW4VmhY%2B8OA_TcHdn=
[email protected]">CALSGBWW4VmhY+8OA_TcHdnnKWWQDG=
[email protected]</a>><br>
Content-Type: text/plain; charset=3D"utf-8"<br>
<br>
Hi,<br>
=C2=A0We ran into a problem where connection to mysql database is not timin=
g out<br>
within specified SQL_ATTR_LOGIN_TIMEOUT value even when the database is not=
<br>
reachable.<br>
<br>
=C2=A0We use UNixODBC driver manager and mysql odbc driver to connect to th=
e<br>
mysql database. In order to make a connection to the database we do the<br>
following<br>
1) Allocate Handle<br>
2) Set SQL_ATTR_LOGIN_TIMEOUT to 5 seconds by calling SQLSetConnectAttr<br>
3) Call SQLDriverConnect to make the connection.<br>
<br>
To debug the issue, I first enabled the trace logs and then started to look=
<br>
at the source code of unix odbc driver manager.<br>
<br>
By looking at the SQLDriverConnectW.c code, looks like the<br>
attribute SQL_ATTR_LOGIN_TIMEOUT is only saved to an internal variable as<b=
r>
long as the connection state is C2.<br>
<br>
And SQLDriverConnectW.c is trying to load the driver as part pf<br>
"part_one_connection" and then trying to make SQLDriverConnectW c=
all to the<br>
mysql odbc driver. So, looks like SQL_ATTR_LOGIN_TIMEOUT is being ignored<b=
r>
and will never be passed on to mysql driver unless the connection state is<=
br>
something other than C2. Looking at the code connection state would be<br>
moved out of S2 state only after a successful connect request to the driver=
<br>
<br>
I believe this is the reason why login timeout is not getting honoured.<br>
<br>
So, to confirm that, I made a change in SQLDriverConnectW to call the mysql=
<br>
driver to set the login timeout(which was saved to internal variable in=C2=
=A0 an<br>
earlier call) after loading the driver but before making the actual<br>
connection. Afer this change, value set for SQL_ATTR_LOGIN_TIMEOUT started<=
br>
to work.<br>
<br>
I am not convinced driver manager would ignore the timeout and I suspect I<=
br>
am doing something wrong. I could not find the reason after going through<b=
r>
the code multiple times over last few days.<br>
<br>
Can someone please point me to the right direction? How does the driver<br>
manager set the connection timeout to mysql driver? Any help is much<br>
appreciated!.<br>
<br>
Thanks in advance<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href=3D"http://mailman.unixodbc.org/pipermail/unixodbc-dev/atta=
chments/20160322/0b6b7e28/attachment-0001.html" rel=3D"noreferrer" target=
=3D"_blank">http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/=
20160322/0b6b7e28/attachment-0001.html</a>><br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Tue, 22 Mar 2016 01:12:21 -0700<br>
From: Satheesh Subramanian <<a href=3D"mailto:[email protected]">sat=
[email protected]</a>><br>
Subject: Re: [unixODBC-dev] SQL_ATTR_LOGIN_TIMEOUT behaviour<br>
To: <a href=3D"mailto:[email protected]">unixodbc-dev@mailm=
an.unixodbc.org</a><br>
Message-ID:<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <<a href=3D"mailto:CALSGBWXwrbEkYfoDQDURFvYu=
[email protected]">CALSGBWXwrbEkYfoDQDURFvYu3S1pKK6=
[email protected]</a>><br>
Content-Type: text/plain; charset=3D"utf-8"<br>
<br>
Please note we are using<br>
unixODBC version : 2.3.1<br>
mysql odbc driver version : 5.3.4<br>
<br>
On Tue, Mar 22, 2016 at 12:34 AM, Satheesh Subramanian <<br>
<a href=3D"mailto:[email protected]">[email protected]</a>> wrot=
e:<br>
<br>
> Hi,<br>
>=C2=A0 We ran into a problem where connection to mysql database is not =
timing<br>
> out within specified SQL_ATTR_LOGIN_TIMEOUT value even when the databa=
se is<br>
> not reachable.<br>
><br>
>=C2=A0 We use UNixODBC driver manager and mysql odbc driver to connect =
to the<br>
> mysql database. In order to make a connection to the database we do th=
e<br>
> following<br>
> 1) Allocate Handle<br>
> 2) Set SQL_ATTR_LOGIN_TIMEOUT to 5 seconds by calling SQLSetConnectAtt=
r<br>
> 3) Call SQLDriverConnect to make the connection.<br>
><br>
> To debug the issue, I first enabled the trace logs and then started to=
<br>
> look at the source code of unix odbc driver manager.<br>
><br>
> By looking at the SQLDriverConnectW.c code, looks like the<br>
> attribute SQL_ATTR_LOGIN_TIMEOUT is only saved to an internal variable=
as<br>
> long as the connection state is C2.<br>
><br>
> And SQLDriverConnectW.c is trying to load the driver as part pf<br>
> "part_one_connection" and then trying to make SQLDriverConne=
ctW call to the<br>
> mysql odbc driver. So, looks like SQL_ATTR_LOGIN_TIMEOUT is being igno=
red<br>
> and will never be passed on to mysql driver unless the connection stat=
e is<br>
> something other than C2. Looking at the code connection state would be=
<br>
> moved out of S2 state only after a successful connect request to the d=
river<br>
><br>
> I believe this is the reason why login timeout is not getting honoured=
.<br>
><br>
> So, to confirm that, I made a change in SQLDriverConnectW to call the<=
br>
> mysql driver to set the login timeout(which was saved to internal vari=
able<br>
> in=C2=A0 an earlier call) after loading the driver but before making t=
he actual<br>
> connection. Afer this change, value set for SQL_ATTR_LOGIN_TIMEOUT sta=
rted<br>
> to work.<br>
><br>
> I am not convinced driver manager would ignore the timeout and I suspe=
ct I<br>
> am doing something wrong. I could not find the reason after going thro=
ugh<br>
> the code multiple times over last few days.<br>
><br>
> Can someone please point me to the right direction? How does the drive=
r<br>
> manager set the connection timeout to mysql driver? Any help is much<b=
r>
> appreciated!.<br>
><br>
> Thanks in advance<br>
><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href=3D"http://mailman.unixodbc.org/pipermail/unixodbc-dev/atta=
chments/20160322/94ebbdad/attachment-0001.html" rel=3D"noreferrer" target=
=3D"_blank">http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/=
20160322/94ebbdad/attachment-0001.html</a>><br>
<br>
------------------------------<br>
<br>
Message: 3<br>
Date: Tue, 22 Mar 2016 10:01:24 +0000<br>
From: Nick Gorham <<a href=3D"mailto:[email protected]">[email protected]<=
/a>><br>
Subject: Re: [unixODBC-dev] SQL_ATTR_LOGIN_TIMEOUT behaviour<br>
To: <a href=3D"mailto:[email protected]">unixodbc-dev@mailm=
an.unixodbc.org</a><br>
Message-ID: <<a href=3D"mailto:[email protected]">56F117F4.90=
[email protected]</a>><br>
Content-Type: text/plain; charset=3D"windows-1252"; Format=3D&quo=
t;flowed"<br>
<br>
On 22/03/16 07:34, Satheesh Subramanian wrote:<br>
> Hi,<br>
>=C2=A0 We ran into a problem where connection to mysql database is not<=
br>
> timing out within specified SQL_ATTR_LOGIN_TIMEOUT value even when the=
<br>
> database is not reachable.<br>
><br>
>=C2=A0 We use UNixODBC driver manager and mysql odbc driver to connect =
to<br>
> the mysql database. In order to make a connection to the database we<b=
r>
> do the following<br>
> 1) Allocate Handle<br>
> 2) Set SQL_ATTR_LOGIN_TIMEOUT to 5 seconds by calling SQLSetConnectAtt=
r<br>
> 3) Call SQLDriverConnect to make the connection.<br>
><br>
> To debug the issue, I first enabled the trace logs and then started to=
<br>
> look at the source code of unix odbc driver manager.<br>
<br>
Well, checking here with the current build (and I dont see any changes<br>
that would affect this) __connect_part_one() contains<br>
<br>
=C2=A0 =C2=A0 =C2=A0/*<br>
=C2=A0 =C2=A0 =C2=A0 * set any connection atributes<br>
=C2=A0 =C2=A0 =C2=A0 */<br>
<br>
=C2=A0 =C2=A0 =C2=A0DO_ATTR( connection, access_mode, SQL_ATTR_ACCESS_MODE,=
<br>
SQL_ACCESS_MODE );<br>
*=C2=A0 =C2=A0 DO_ATTR( connection, login_timeout, SQL_ATTR_LOGIN_TIMEOUT,<=
br>
SQL_LOGIN_TIMEOUT );*<br>
=C2=A0 =C2=A0 =C2=A0DO_ATTR( connection, auto_commit, SQL_ATTR_AUTOCOMMIT,<=
br>
SQL_AUTOCOMMIT );<br>
=C2=A0 =C2=A0 =C2=A0DO_ATTR( connection, async_enable, SQL_ATTR_ASYNC_ENABL=
E,<br>
SQL_ASYNC_ENABLE );<br>
=C2=A0 =C2=A0 =C2=A0DO_ATTR( connection, auto_ipd, SQL_ATTR_AUTO_IPD, 0 );<=
br>
=C2=A0 =C2=A0 =C2=A0DO_ATTR( connection, connection_timeout,<br>
SQL_ATTR_CONNECTION_TIMEOUT, 0 );<br>
=C2=A0 =C2=A0 =C2=A0DO_ATTR( connection, metadata_id, SQL_ATTR_METADATA_ID,=
0 );<br>
=C2=A0 =C2=A0 =C2=A0DO_ATTR( connection, packet_size, SQL_ATTR_PACKET_SIZE,=
<br>
SQL_PACKET_SIZE );<br>
=C2=A0 =C2=A0 =C2=A0DO_ATTR( connection, quite_mode, SQL_ATTR_QUIET_MODE, S=
QL_QUIET_MODE );<br>
=C2=A0 =C2=A0 =C2=A0DO_ATTR( connection, txn_isolation, SQL_ATTR_TXN_ISOLAT=
ION,<br>
SQL_TXN_ISOLATION );<br>
<br>
And SQLSetConnectAttr.c contains<br>
<br>
=C2=A0 =C2=A0 =C2=A0/*<br>
=C2=A0 =C2=A0 =C2=A0 * we need to save this even if connected so we can use=
it for the<br>
next connect<br>
=C2=A0 =C2=A0 =C2=A0 */<br>
=C2=A0 =C2=A0 =C2=A0if ( attribute =3D=3D SQL_ATTR_LOGIN_TIMEOUT )<br>
=C2=A0 =C2=A0 =C2=A0{<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0connection -> login_timeout =3D ( SQLL=
EN ) value;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0connection -> login_timeout_set =3D 1;=
<br>
=C2=A0 =C2=A0 =C2=A0}<br>
<br>
And the comment when this was changed<br>
<br>
=C2=A0 * Revision 1.4=C2=A0 2002/01/10 11:17:20=C2=A0 lurcher<br>
=C2=A0 *<br>
=C2=A0 * Allow SQL_ATTR_LOGIN_TIMEOUT to be set when connected to mirror wh=
at the<br>
=C2=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<br>
to work as I would expect, calling SQLSetConnect in the driver between<br>
the SQLAllocEnv( SQL_CONNECT ) and the SQLConnect/SQLDriverConnect<br>
<br>
--<br>
Nick<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href=3D"http://mailman.unixodbc.org/pipermail/unixodbc-dev/atta=
chments/20160322/7fd504f7/attachment-0001.html" rel=3D"noreferrer" target=
=3D"_blank">http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/=
20160322/7fd504f7/attachment-0001.html</a>><br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
unixODBC-dev mailing list<br>
<a href=3D"mailto:[email protected]">[email protected]=
nixodbc.org</a><br>
<a href=3D"http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev" rel=
=3D"noreferrer" target=3D"_blank">http://mailman.unixodbc.org/mailman/listi=
nfo/unixodbc-dev</a><br>
<br>
<br>
End of unixODBC-dev Digest, Vol 104, Issue 6<br>
********************************************<br>
</blockquote></div><br></div>
--001a1143614a0f9ea3052ea54f4e--
--===============1440114994==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
unixODBC-dev mailing list
[email protected]
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev
--===============1440114994==--