167
Views
7
Comments
Solved
Database connection error
Question

Is it possible to catch database connection error when the server is not available. There is an aggregate in a screen preparation I want to catch when the database server is not available, but the error is not caught in the local action nor the OnException in Common UI flow.

Version 10.0.807.0

Solution

I think setting up a simple monitoring solution with a good followup is the way to handle this. Like Kilian was saying Outsystems uses more db actions even before the page is going to the preparation so probably you will get a nice IIS error page.

mvp_badge
MVP
Rank: #2

Hi Stanley,

With Web Apps the Platform assumes the database is always available. So I don't think it's possible to gracefully catch a situation where it isn't.

Rank: #1990

This is definitely less than desirable. 

Here is my solution: create a REST API to query the database, call the API in the screen preparation and caught the REST API exception.

mvp_badge
MVP
Rank: #2

Hi Stanley,

Not sure whether that would work. The Platform accesses the database when the screen starts, you'll be "dead" before you get a chance to even call the REST API. Also, if you have database connection problems on a regular basis, your infrastructure is botched, and there's better things you can do than call REST APIs in every screen...

Solution

I think setting up a simple monitoring solution with a good followup is the way to handle this. Like Kilian was saying Outsystems uses more db actions even before the page is going to the preparation so probably you will get a nice IIS error page.

Rank: #1990

Hi Kilian and Peter,

Thanks for your replies. 

I should state the database is external, not the native database. Of course it cannot be done within the application for the native database, but my solution works for external databases.

Cheers!

Rank: #19004

Hi Stanley,

Did you ever resolve this (appreciate it was 2+ years ago....).

I'm hitting a similar issue, I have an Azure SQL database which goes to pause state after 1 hour of inactivity. I want to check it is awake with a simple aggregate. If it is;t awake, one query to it brings it back online.

My current approach (which doesn't work):

On login I have a server action with a timeout of 30 seconds & within that server action I have an aggregate with a timeout of 5 seconds. I expected the aggregate to timeout first, but I can never seem to trigger the timeout exception of the aggregate using a Communication Exception or even All Exceptions in the server action. Instead a communication exception is trigger on timeout of the server action after 30 seconds.

My intended application was that if a Communication Exception is triggered the server action should respond success=false, wait for 5 seconds, the try again. Sat in a  loop for 5 attempts, after which it triggers a higher level exception.

How could I go about this?

Rank: #1990

Hi Steve,

I did what I said, create an API to check the database connection in preparation before tries to retrieve data. The trick is to time out in the API before the database connection which usually defaults to 5 minutes. The API is separated from the app for reusable. It's been two years, you should check any updates in the new version to handle this as Peter's reply.