SQL Timeout expired for 2 second query SQL Timeout expired for 2 second query asp.net asp.net

SQL Timeout expired for 2 second query


Your connection from SQL Management studio may be configured differently from the connection string you're using from .NET.

For example, see the options that are set by default in SQL Management Studio Tools/Options/Query Execution/SQL Server/Advanced.

I would suspect some setting that is different between the two environments is causing your problem. To debug you should try to configure SQL Server Management Studio to use the same configuration as your .NET connection string before running your SP.

Or alternatively, add SET statements to your .NET query to configure all the options you see configured in Management Studio.

It's not always easy to find the setting that's different - in my experience a common cause is different ANSI settings.


Is it a stored procedure? In SSMS did you run the stored procedure or just the query. I have come across Paramter Sniffing in SQL that could potentially cause long running Store procedure. Google parameter sniffing and you will find option on how to avoid it.Its assigning the parameter to a local variable inside SP and using them instead of the actual parameters