Solved

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

Posted on 2014-03-25
8
1,036 Views
Last Modified: 2014-04-11
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.

Thanks,
Bruce
0
Comment
Question by:Bruce
8 Comments
 
LVL 21

Assisted Solution

by:Craig Wagner
Craig Wagner earned 125 total points
Comment Utility
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.
0
 
LVL 39

Accepted Solution

by:
lcohan earned 375 total points
Comment Utility
"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.

http://msdn.microsoft.com/en-us/library/ff650699.aspx
0
 
LVL 1

Author Comment

by:Bruce
Comment Utility
It returns just two rows of 12 columns of data.  Small about really...
0
 
LVL 1

Author Comment

by:Bruce
Comment Utility
Why wouldn't a 2 minute command timeout eventually consume a 12 second SQL query?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 39

Assisted Solution

by:lcohan
lcohan earned 375 total points
Comment Utility
"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:

sp_who2;
0
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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();
sda.Fill(tbl);
0
 
LVL 1

Author Comment

by:Bruce
Comment Utility
SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            conn.Close();
            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.

Thoughts?
Timeout-Exception-CommDetail.PNG
Client-Stats-CommDetail.PNG
0
 
LVL 1

Author Comment

by:Bruce
Comment Utility
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.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now