Why is there an SQL timeout only when running from Visual Studio after modifying code.

Ken Smith 230 Reputation points
2024-01-01T18:57:34.21+00:00

This happens only with a large Windows App. If I have Visual Studio open and I change a simple line of code and then run my app, it gets a timeout 95% of the time. If I close Visual Studio and re-open and run the app then it works. It is frustrating; I now do a build then shutdown Visual Studio and restart Visual Studio so I can run the app without waiting 60 seconds for the timeout. The app never times out in production or on my desktop if Visual Studio is not running. Can anyone tell me how to determine what causes this timeout?

enter image description here

Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other
A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.
SQL Server | Other
{count} votes

Answer accepted by question author
  1. Erland Sommarskog 128.7K Reputation points MVP Volunteer Moderator
    2024-01-04T23:03:05.22+00:00
    1. Version of SQL Server (stayed on 2008 R2 because 2012 caused nightmares with IDENTITY column jumping by thousands).

    That is nothing you should care about. The IDENTITY feature exist to permit high-concurrent inserts into a table, and it is designed to produce gaps. It writes the current value to disk only for every thousand rows, exactly to make things quicker. It is intended for surrogate keys where you don't care about the values. If you care about the values, you should not use IDENTITY, but roll your own.

    (There is an option to turn of caching, but why would you press a go-slower button?)

    And you can't stay on SQL 2008 R2 forever. It is out of support and outdated. Time to move on.

    As for your issue, it is as I started to suspect. The RESOURCE_SEMAPHORE waits together the information that you have 8 GB of RAM tells me that you are low on memory. You could check in Task Manager how much RAM Visual Studio takes up. But now that it is 64-bit, it can ask for quite a bit I guess. Personally, I would not like a laptop with less than 32 GB of RAM.


1 additional answer

Sort by: Most helpful
  1. Erland Sommarskog 128.7K Reputation points MVP Volunteer Moderator
    2024-01-01T19:28:17.2966667+00:00

    My prime guess would be a blocking issue. Somehow you have left something with an open transaction, and then the app gets blocked on that open transaction.

    Make sure you have SSMS or Azure Data Studio running. Do your Visual Studio thing and start the app. Run sp_who. Keep an eye on the Blk column. It there is a number in that column. that is the spid on that row.

    You can also use my beta_lockfinfo which gives you a lot more details, including locks, so you can see what the process is waiting on. You also see the current query and its query plan, in case this is a query-plan issue (which would be the other alternative.)


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.