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

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

Postby 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
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?

Postby 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/en-US/adodotnetentityframework/thread/6fe91a64-0208-4ab8-8667-d061af340994/.
Shalex
Devart Team
 
Posts: 7774
Joined: Thu 14 Aug 2008 12:44

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

Postby TonyV » Mon 02 Jul 2012 14:36

Thank you for the response. Now to run with it.
TonyV
 
Posts: 74
Joined: Wed 25 May 2011 15:03


Return to dotConnect for PostgreSQL