How does the connection to the database work

Posts   
 
    
joshmag
User
Posts: 14
Joined: 20-Aug-2021
# Posted on: 08-Sep-2021 02:15:31   

Hi,

We have a web service that talks to a Sybase database. We are using LLBLGEN 5.2 as our ORM.

I have noticed that if the web service is idle for a long time (maybe 2 hours), and then someone calls it, we get the following socket error:

Sybase.Data.AseClient.AseException: Connection to Sybase server has been lost. Connection died while reading from socket. Socket returned error code 10054. ERRNO returned 0. All active transactions have been rolled back

I am not sure what's going on, but I think that either LLBLGEN or the driver tries to use just one socket connection for all requests, and if the socket dies, then you get the following read error. Is this true? Could someone please explain to me how the connection to Sybase actually works?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 08-Sep-2021 09:30:07   

We don't do any socket related actions, we call the Open() method on the DbConnection instance of the Sybase provider. Most ADO.NET providers keep a pool of open connections to the database ('connection pooling') and map one of those open connections into a new DbConnection instance of the ADO.NET provider. So we communicate to the DbConnection instance (the sybase provider, like all other ado.net providers, use a derived class of that class) and the DbConnection object communicates with the database.

So this is an error caused by Sybase code. One of the reasons we stopped supporting Sybase some time ago is that their ADO.NET provider is very buggy.

Frans Bouma | Lead developer LLBLGen Pro
joshmag
User
Posts: 14
Joined: 20-Aug-2021
# Posted on: 08-Sep-2021 16:02:59   

I see. Thanks. Is there a way for me to reset the connection? I guess I will try running a background thread every minute that makes a simple query to the database, which should hopefully keep the socket open. If that doesn't work, I will have to put a try catch around ever database access and retry if it fails...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 09-Sep-2021 08:32:46   

there's no way you can 'reset' a pooled connection. A try / catch is the best approach as it might also be that the db server is offline for instance.

Frans Bouma | Lead developer LLBLGen Pro
joshmag
User
Posts: 14
Joined: 20-Aug-2021
# Posted on: 10-Sep-2021 02:04:17   

Otis wrote:

there's no way you can 'reset' a pooled connection. A try / catch is the best approach as it might also be that the db server is offline for instance.

ok, but wrapping each database call in a try catch seems annoying. The Sybase driver should just try again. Oh well.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 10-Sep-2021 09:13:36   

joshmag wrote:

Otis wrote:

there's no way you can 'reset' a pooled connection. A try / catch is the best approach as it might also be that the db server is offline for instance.

ok, but wrapping each database call in a try catch seems annoying. The Sybase driver should just try again. Oh well.

You could contact Sybase?

Frans Bouma | Lead developer LLBLGen Pro
joshmag
User
Posts: 14
Joined: 20-Aug-2021
# Posted on: 20-Oct-2021 05:31:54   

Thanks, but they won't help me.

Anyway, I just added code at the start of each request which re-establishes the connection, and it has fixed the issue.