Page 1 of 1

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

Posted: Sat 23 Jun 2012 02:07
by TonyV
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

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

Posted: Mon 02 Jul 2012 14:12
by Shalex
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/.

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

Posted: Mon 02 Jul 2012 14:36
by TonyV
Thank you for the response. Now to run with it.