Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1197
  • Last Modified:

How do I diagnose the Timeout of a SQL command called from my C# web service app

I am calling a stored proc in a MS SQL server database that, when run in SSMS, takes 12 seconds.  The SqlCommand object I am using to call the stored proc times out when I call from my C# webservice.  I have up'd the CommandTimeout to 120 seconds but get the same result....

SqlCommand cmd = new SqlCommand(procName, conn) {CommandType = CommandType.StoredProcedure, CommandTimeout = 120};
SqlDataAdapter sda = new SqlDataAdapter(cmd);

Open in new window

How do I go about determining the bottleneck?  

Again, this proc will execute to completion in SSMS in 12 seconds.

3 Solutions
Craig WagnerSoftware ArchitectCommented:
First thing I would do is fire up SQL Server Profiler and make sure that what you think your code is sending to the database is actually what your code is sending to the database.
lcohanDatabase AnalystCommented:
"Again, this proc will execute to completion in SSMS in 12 seconds."
How much data it returns? could this be the issue?

"How do I go about determining the bottleneck?  "
I suggest you use SQL Profiler to trace any call to that SQL Sproc.

BruceAuthor Commented:
It returns just two rows of 12 columns of data.  Small about really...
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

BruceAuthor Commented:
Why wouldn't a 2 minute command timeout eventually consume a 12 second SQL query?
lcohanDatabase AnalystCommented:
"Why wouldn't a 2 minute command timeout eventually consume a 12 second SQL query? "

How can you be 100% sure that the "timeout" IS the actual error and not something else and...Are you sure is running against that exact Server database and doing what is supposed to?

Here - start your UI code and run a sp_who2 in a SQL SSMS query OR check SQL Activity Monitor in SSMS to see that indeed you are running that SP against that SQL Database.

just type the command below in a SQL SSMS query and check its results:

Jacques Bourgeois (James Burger)PresidentCommented:
Do you have more code after what you showed us.

The SqlDataAdapter alone does not execute the command. You need to Fill a DataTable for it to execute the command:

DataTable tbl = New DataTable();
BruceAuthor Commented:
SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            return ds;

Open in new window

Per the mention above from lcohon I have have opened SSMS and did an sp_who2 while the Fill command was called...  I watch the Login that my app uses (unique in this environment) and the CPUTime just keeps counting up to the 240 sec timeout limit I set in the code.

I have tried to implement a SQLDataReader, thinking the Forward Only nature of that reader might reduce the overhead in returning the data.  There should be less than 1KB returned (See attached Clients Stats screenshot)  The Reader also times out.

BruceAuthor Commented:
Update: We had a similar issue with another SP being called from our web service app.  The sp would run from within SSMS in a short time, but when called from the service it would hang. (Verified in SQL Analyzer, processes would contiuously run (Task State RUNNING) in "SELECT INTO" command) We found that the web service was passing in an empty string as one of the parameters and it was not being handled well in the sp and that was causing the sp to timeout.

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now