Can anyone please suggest possible reasons for a sql query timeout while debugging in Visual Studio, considering that the same query always runs as expected in SSMS, the same in VS without debugging as well as while running installed desktop application.
The sql query is quite long so giving a simplified example.
SELECT t1.field1, t2.field1, t3.field1, t4.field1 FROM
table1 t1 INNER JOIN table2 t2 ON t1.id = t2.id INNER JOIN
table3 t3 on t1.id = t3.id INNER JOIN table4 t4 ON t1.id = t4.id
WHERE t3.char = ‘N’ AND t4.id2 = 1
The query only pulls about 500 records so the usual execution time is under 1s. I had the sql string excecuted from a variable, also tried to adjust the program to run it from a stored procedure and a table function, all three options result in the same timeout in VS while using debugging mode only.
When the problem occurs, the sql execution queue is blocked and unless I stop the debugging mode and sometimes even having to restart VS, no sql commands can complete in SSMS.
The C# code is
using (IDbConnection db = new SqlConnection(myconnection))
{
return new ObservableCollection<MY_INFO>(db.Query<MY_INFO>
("exec sp_mysp @MY_ID", new { MY_ID = myid }, commandTimeout: 60).ToList());
}