0

I have an ASP.NET Core application, using Entity Framework Core, I am accessing my SQL Server database.

All of the sudden, in the last couple of days, an issue arose where there is a specific table that is causing blocking queries.

My application processes orders, every order needs to have a specific number, which has to be unique per day.

Every time an order is placed, I add an entity to the table if no entity can be found for the specified date and if an entity can be found I update the order number.

Entity: OrderAtDay

public int CurrentAmountOfOrders { get; set; }
public DateTime Date { get; set; }

The blocking query occurs sometimes when I am checking if an existing entity exists, and sometimes it occurs when trying to update the entity with the increased number (when SaveChangesAsync is called).

When this issue occurs, there is no other option than to kill the blocking query with the following SQL queries:

SELECT 
    blocking_session_id AS BlockerSession, 
    session_id AS BlockedSession 
FROM 
    sys.dm_exec_requests 
WHERE 
    blocking_session_id <> 0;

If the previous query would return "57" for example as the blocking_session_id, I would then kill it with the following query (then sometimes there is multiple times the data can be accessed, before being blocked suddenly again):

Kill 57

Things I have tried:

  • Resource Management: Making sure the server has plenty of resources
  • Enabled READ_COMMITTED_SNAPSHOT
  • Clear the entire plan cache using DBCC FREEPROCCACHE;
  • Update statistics: EXEC sp_updatestats
  • New SQL Server instance
  • Clear the problematic table completely
  • Drop and re-create the problematic table

Has anyone else ever faced this issue, or are there any ways to prevent / work around this behaviour?

I have multiple copies of the same application running for different users (+- 35 times) and no other users are facing this issue.

I think it is pretty strange that only this particular table in this particular database is facing this issue. Any help is much appreciated

5
  • Why not check what's the blockage is? You're using a nuke to kill a bug right now. Check DBCC OPENTRAN and Activity Monitor (or sp_whoIsActive and friends) to see which queries are running and what's blocking what. Commented Sep 11, 2024 at 20:47
  • Hello @siggemannen, i do believe we are able to identity a blocking query, but we are unsure how we can resolve this issue, there are many questions we have, such has "why does it suddently occur out of nowhere?", "why does it only happen to this database and not the 35 others?", "how ca nwe prevent this from happening to other tables?" , the query really is not that complex, so we are afraid it might happen to other tables in our database aswell Commented Sep 12, 2024 at 6:00
  • I think it can be a couple of cases. 1) someone opening a transaction against a table and then going out to lunch 2) some other slow but legitimate process doing some updates on your table 3) some internal sql server goo gluing your process at bay 4) bug in your application that holds transactions in place 5) something else. Once you figure which one it is, you can probably figure out what to do. It's hard to answer with more details because it all depends but you can always come back and update this question or create a new own with specifics. Commented Sep 12, 2024 at 6:30
  • @siggemannen thank you, as there are no people working directly on the sql server (only our app), and it is only this particular database and not the 35 others, i believe it could be option number 3, do you have any resources on how to start looking into this option? Commented Sep 12, 2024 at 6:55
  • I think they all come down to same thing. See which process is blocking your query, see the query of the process, and then go from there. I'm pretty sure it's not #3, unless you're on azure / bad hardware. But anyway, this microsoft article was pretty good to see the blocking. Otherwise, as i wrote, DBCC OPENTRAN, Activity Monitor etc is good. Commented Sep 12, 2024 at 6:59

0

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.