ODBC questions

Michael McDaniel <>
Thu Feb 9 19:58:13 CET 2006


On Sun, Feb 05, 2006 at 04:39:12PM +0100, Mickael Remond wrote:
> Hello,
> 
> I have recently been working a lot with ODBC and Erlang. One problem /
> question remains: Is there any mechanism to detect when the connection
> to the database is lost ? The purpose is to be able to try restarting
> the connection.
> I looked at the ODBC code, but did not find any relevant parts.
> For now, the behaviour seems to be the following: When querying a
> database who went offline, I get an error as the query response. The
> text of the error explains that the database is not more reachable but
> the ODBC process is still there.
> 
> I suspect that such reconnection mechanism should be handled by the ODBC
> driver. I have been doing my tests with MySQL. 
> 
> Does someone here have experienced the same reconnection problem with
> ODBC ? 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I (perhaps naively) do the following in a (reliable) production system:


readUpdateQuarry(Ref, CacheCallid, NewCallid) ->

Z = "insert into quarry select "  etc. etc. proprietary stuff

  case odbc:sql_query(Ref, Z) of
    {updated, Return} -> {updated, Return} ;
    {_, Error}        -> expmaster:log_error(?MODULE, ?LINE,
				 'odbc:sql_query', Error) ,
		         {error, Error}
  end
.


where Ref is an ODBC connection.  Everything works fast enough for
this system for the calling function to disconnect/reconnect if
there is a problem.

Other insert/query functions I have will create a new connection
and destroy the connection for each call.  This is fast enough
in my production environment also.  I originally had designed
to have a process that marshalled ODBC connections for the workers.
That proved to be more hassle than it was worth since the above
simpler system works plenty fast enough. 


~Michael


> 
> -- 
> Mickaël Rémond
>  http://www.process-one.net/

-- 
Michael McDaniel
Portland, Oregon, USA
http://autosys.us
+1 503 283 5284



More information about the erlang-questions mailing list