Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 661215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:14:35+00:00 2026-05-13T23:14:35+00:00

I’m getting a timeout error when trying to execute a LINQ (-to-SQL) query System.Data.SqlClient.SqlException:

  • 0

I’m getting a timeout error when trying to execute a LINQ (-to-SQL) query

System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

Now, this is not just a case of a slow query:

  • I run the equivalent SQL in SQL Management Studio and it completes quickly (2 seconds)
  • I’m setting my CommandTimeout to 2 minutes.
  • When I execute the very same query in a unit test, it completes successfully and quickly. That is: I’m only getting this timeout when I’m running this query alongside other queries. The timeout always occurs at the same call.

That last item made me think that I’m getting some sort of database-side deadlock: the query is blocked by a lock somewhere, and the timeout period elapses, killing the stalled connection.

The trouble with this idea is that I’m only doing selects in the DataContext that’s causing problems. (I do have inserts occurring in a different database/DataContexts.) I also have no explicit transactions. This is tripping me up a bit: the query behavior looks exactly like a deadlock, but I’ve never had a deadlock that wasn’t caused by some sort of transaction isolation issue before — and that doesn’t look like the case here (at first glance anyway).

I’m looking for advice on how to debug this problem. What sorts of things should I be looking at to determine the cause of this problem?

EDIT

Some notes that may be useful:

  • I’m querying against a view that references:
    • Other views in the same database
    • Synonyms that point to tables in another database via a Linked Server.
  • This view is using union to join the results of several queries together

EPILOGUE

I ended up fixing the core problem by reworking my query. The original was calling a few tables more than once (via different views). The reworked version bypassed all of this, and the timeouts disappeared.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:14:35+00:00Added an answer on May 13, 2026 at 11:14 pm

    run your code again from the application, while it is waiting (for 2 minutes??) run this in a query window:

    ;with Blockers AS
    (SELECT
         r.session_id AS spid
             ,r.cpu_time,r.reads,r.writes,r.logical_reads 
             ,r.blocking_session_id AS BlockingSPID
             ,LEFT(OBJECT_NAME(st.objectid, st.dbid),50) AS ShortObjectName
             ,LEFT(DB_NAME(r.database_id),50) AS DatabaseName
             ,s.program_name
             ,s.login_name
             ,OBJECT_NAME(st.objectid, st.dbid) AS ObjectName
             ,SUBSTRING(st.text, (r.statement_start_offset/2)+1,( (CASE r.statement_end_offset
                                                                       WHEN -1 THEN DATALENGTH(st.text)
                                                                       ELSE r.statement_end_offset
                                                                   END - r.statement_start_offset
                                                                  )/2
                                                                ) + 1
                       ) AS SQLText
         FROM sys.dm_exec_requests                          r
             JOIN sys.dm_exec_sessions                      s ON r.session_id = s.session_id
             CROSS APPLY sys.dm_exec_sql_text (sql_handle) st
         --WHERE r.session_id > 50
    )
    SELECT Blockers.* FROM Blockers
    

    it will show you all the blocks at the time of the run.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 368k
  • Answers 368k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Disclaimer: my answer is possibly relevant only to pre-WPF .NET… May 14, 2026 at 5:08 pm
  • Editorial Team
    Editorial Team added an answer WebParts are all controls, so you can add a web… May 14, 2026 at 5:08 pm
  • Editorial Team
    Editorial Team added an answer It seems to me, that you are not waiting for… May 14, 2026 at 5:08 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.