0

I've just randomly started getting this issue, and previously it has been fine up until tonight. I do not want to touch the timeout stuff, I believe it's not needed.

It's a simple query.

{"Timeout expired.  The timeout period elapsed prior to completion of the 
operation or the server is not responding."}

Here is the code causing the timeout..

   var post = (from p in con.blog_posts 
                    orderby p.post_dt descending 
                    select p).First();

Can anyone think of any crevices I should check to try an resolve this?

edit: I can connect to the server with management studio and it is up..

3
  • How many records are there in the table? Commented Aug 11, 2011 at 3:07
  • You say 'it's been fine up until tonight' - what changed tonight? Did the code change, did you add more data, did anything at all change? Commented Aug 11, 2011 at 3:17
  • The query doesn't timeout and works flawlessly when it's ran from a server at work.. I don't really understand maybe it has to do with a connection issue I'm at school at the moment... Commented Aug 11, 2011 at 3:36

2 Answers 2

1

you could avoid the sort:

var post = 
    from p in con.blog_posts
    where p.post_dt == con.blog_posts.Max(post=>post.post_dt) 
    select p
Sign up to request clarification or add additional context in comments.

8 Comments

I believe the order by will be at least as fast, if not faster, since it'll be translated into SQL and executed in the database. I do not know whether the Max will be translated into a single SQL statement along with the select - and even if it is, it won't be quicker than a simple SELECT TOP 1 ORDER BY
yar good point, I tested in linqpad afterwards and you are correct - I'll delete this post
hmm...actually I tested again five times for each query: the Max method was slightly faster on average (~540ms vs ~640ms for 2.2M rows) - but given the OPs comment that there are only 3 rows, this is clearly not the solution.
I believe the issue is because I'm behind my school's connection, when ran from another connection it's fine...
@saus I find it hard to believe the order by would be slower when the table is indexed. And you would never order by 2M rows without an index.
|
1

Are other database queries working as expected? Go to your database and run that query and see how long it takes to return. Try to run the exact query (capture it in SQL Profiler). This will tell you if your database is simply performing slowly for this query, or whether it's another issue.

My first guess would be that you don't have an index on the post_dt column. Trying the query directly in SQL will prove or disprove this. If the query takes a long time to run, add a nonclustered index on that column and retry.

2 Comments

the SQL query performance is great, this table only has 3 records.
You ran the same query that is generated from your application, captured in SQL Profiler or similar?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.