What is the exact exception and message that is thrown if a query times out?

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
TonyV
Posts: 74
Joined: Wed 25 May 2011 15:03

What is the exact exception and message that is thrown if a query times out?

Post by TonyV » Sat 23 Jun 2012 02:07

I haven't actually looked at this error too often, but I believe I need to trap this condition in one particular query in my application. We are expecting our software to be installed on some slow syistems with only 500 MB of RAM. I'm expecting that this one particular query is going to time out a lot and I need to handle the condition properly. Unfortunately, my workstation has 4 GB and 2 cores and is clocked at almost 3 GHz.

SO what exactly do I need to catch and how do I know for sure that it's a timeout exception?

BTW, the query is generated using an Entity Framework 4.0 context developed using Entity Developer. We're using build 5.80.350.0.

Tony

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: What is the exact exception and message that is thrown if a query times out?

Post by Shalex » Mon 02 Jul 2012 14:12

TonyV wrote:SO what exactly do I need to catch and how do I know for sure that it's a timeout exception?
1. An example of handling PostgreSQL timeout exception via Entity Framework:

Code: Select all

    using (PostgreEntities context = new PostgreEntities()) {
        context.CommandTimeout = 1;
        try {
            var a = (from b in context.Mytbls.Union(context.Mytbls).Union(context.Mytbls)
                        select b).ToList(); // execution time > 1 second
        }
        catch (EntityException ex) {
            if (ex.InnerException is Devart.Data.PostgreSql.PgSqlException && ex.InnerException.Message == "Server did not respond within the specified timeout interval.") {
                // process the timeout exception
            }
        }
    }
2. If you use DbContext, CommandTimeout could be set in the following way: http://social.msdn.microsoft.com/Forums ... 1af340994/.

TonyV
Posts: 74
Joined: Wed 25 May 2011 15:03

Re: What is the exact exception and message that is thrown if a query times out?

Post by TonyV » Mon 02 Jul 2012 14:36

Thank you for the response. Now to run with it.

Post Reply