Web-App waiting for indefinite timehttp://forums.asp.net/t/1140687.aspx/1?Web+App+waiting+for+indefinite+timeTue, 07 Aug 2007 08:39:05 -040011406871834236http://forums.asp.net/p/1140687/1834236.aspx/1?Web+App+waiting+for+indefinite+timeWeb-App waiting for indefinite time <p>Hi,</p> <p>I have got an interesting problem. It seems to be some architectural bug thats why im placing this post in this forum. I have got an inline query which i try to execute from my web application. Using the SqlCommand &#43; DataSet, i am trying to execute the query but it does not work (will explain the problem shortly). I also placed the same query in a stored procedure, call it from my web app but its not working. The interesting point is that if i execute the same query or stored procedure using Sql Server 2005 environment, they work perfectly alright. But when i try to execute the same query/procedure from my web application, sql server goes in an ever lasting processing loop and then after 30 seconds (default for SqlCommand object), the application comes back with the following error:</p> <p>&quot;Timeout expired.&nbsp; The timeout period elapsed prior to completion of the operation or the server is not responding&quot;</p> <p>I even set the SqlCommand.CommandTimeOut property to 0 (unlimited), but sql server just keeps on processing the request and never returns a result. As i mentioned, the same query/procedure works fine directly within SQL Server 2005 environment, but when i call them from my web app, it just keeps on processing the request. This really amazes me.</p> <p>Any help will be greatly appreciated...</p> 2007-08-01T04:37:05-04:001834419http://forums.asp.net/p/1140687/1834419.aspx/1?Re+Web+App+waiting+for+indefinite+timeRe: Web-App waiting for indefinite time <p>&nbsp;What is the size of the data being returned by your query? Is the DB on the same machine as the web app?<br> </p> <p>-Vivek&nbsp;</p> 2007-08-01T06:31:33-04:001834482http://forums.asp.net/p/1140687/1834482.aspx/1?Re+Web+App+waiting+for+indefinite+timeRe: Web-App waiting for indefinite time <p>Hi Vivik,</p> <p>Thanks for the reply. Well there are hardly 500 rows (each with mere 10 columns) and in the future the rows wont be more than 2000. Yes, the database is on the same machine. As i said above, the query/stored procedure returns the perfect result within SQL 2005 query environment but when executing it through the web-app, it waits indefinitely until it timesout.</p> <p>Let me also add, that the query has got a few nested select statement. When i commented out the nested statements, the page worked fine. For your info, following is a snippet of one of the nested query:</p> <p>SELECT&nbsp;....</p> <p>(</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT &nbsp;SUM&nbsp; (T2.PointsEarned)</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM&nbsp;&nbsp;&nbsp; &nbsp;Table2 T2</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE&nbsp; &nbsp;T2.ID_fk = T1.ID</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;(T2.DateStarted BETWEEN @Date1 AND @Date2)</p> <p>)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TotalPoints,</p> <p>FROM Table1 T1 INNER JOIN ....</p> <p>I wonder if there&nbsp;is a problem with the query, why does it get executed perfectly within SQL Server 2005 query environment. But when calling it through a web-page, it waits forever eventually timing-out. I just have&nbsp;a weired feeling if this is somehow bothering the dataset. I did place a breakpoint on SqlDataAdapter.Fill (DataSet) (last statement before the try ... catch block) and this is where the exception is raised. I mean no data is populated...</p> <p>Thanks...</p> 2007-08-01T07:12:26-04:001836720http://forums.asp.net/p/1140687/1836720.aspx/1?Re+Web+App+waiting+for+indefinite+timeRe: Web-App waiting for indefinite time <p>Hi Khasif,</p> <p>Writing Sub query will always make things complicated from the performance point of view, instead you may use the table variable in your query and populate all sorts of data in that table and return that table from the procedure.</p> <p>Anyways in your case this shouldnt be the problem as&nbsp;there are &nbsp;very less data in your table. Run SQL Profiler to see exactly what query is getting into your db from you application.</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p><br> &nbsp;</p> <p>&nbsp;</p> 2007-08-02T05:22:17-04:001836867http://forums.asp.net/p/1140687/1836867.aspx/1?Re+Web+App+waiting+for+indefinite+timeRe: Web-App waiting for indefinite time <p>Hi Abhishek,</p> <p>Thanks for the reply. You see, this is what has been bothering for me so long. I ran the SQL Profiler and was looking at the query which was being executed. I executed the query (from the sql profiler) in sql management studio and it worked according to my expectation. But when i tried to run it from my web-app, it just hangs out. I even wrote the parameters (only 2 in this case) to a file and they were just fine. Infact, the same parameters could be seen under Sql Profiler.</p> <p>Somehow, Could this be a possible framework bug under ADO.NET (forgive me for my strightforwardness). If the query is working perfectly under sql server and in a stored procedure than it should definitely get called from the web-app. Although now im thinking of rewriting the whole query but it keeps me satiated for a reply.</p> <p>Ok, one more thing, i printed the StackTrace Message from the exception and this is what is making me say in the above paragraph:</p> <p>.........<br> was not returned properly.&nbsp;&nbsp; at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)<br> &nbsp; at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)<br> &nbsp; at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)<br> &nbsp; at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)<br> &nbsp; at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()<br> &nbsp; at System.Data.SqlClient.SqlDataReader.get_MetaData()<br> &nbsp; at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)<br> &nbsp; at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)<br> &nbsp; at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)<br> &nbsp; at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)<br> &nbsp; at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)<br> &nbsp; at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)<br> &nbsp; at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)<br> &nbsp; at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)<br> &nbsp; at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)<br> &nbsp; at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)<br> at .........<br> in ..........</p> <p>In the above case, it seems that the DataSet (from the last few lines) is not getting populated. If the query is well executed in sql studio but not able to return data to the DataSet then this leave me totally confused. Can any guru point out the problem (most probably my mistake).</p> <p>Thanks...</p> 2007-08-02T06:51:28-04:001837009http://forums.asp.net/p/1140687/1837009.aspx/1?Re+Web+App+waiting+for+indefinite+timeRe: Web-App waiting for indefinite time <p>Paste me the whole stored procedure and le me have a look into that</p> <p>&nbsp;</p> 2007-08-02T08:21:30-04:001837188http://forums.asp.net/p/1140687/1837188.aspx/1?Re+Web+App+waiting+for+indefinite+timeRe: Web-App waiting for indefinite time <p>SELECT &nbsp;&nbsp;E.EmpID, E.Name, E.Status_fk, E.Marital_fk, E.Address,</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SELECT&nbsp;&nbsp;SUM (P.HoursWorked) FROM&nbsp;&nbsp;Presence P<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE&nbsp;&nbsp;(P.EmpID_fk = E.EmpID)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND&nbsp;&nbsp;(P.DateWorked Between @JoinDate AND @CurrentDate)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ) &nbsp;&nbsp;&nbsp; TotalHoursWorked,</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT&nbsp;&nbsp;SUM (P.HoursAbsent)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM&nbsp;&nbsp;Presence P<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE&nbsp;&nbsp;(P.EmpID_fk = E.EmpID)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND&nbsp;&nbsp;(P.DateWorked Between @JoinDate AND @CurrentDate)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;) &nbsp;&nbsp; TotalHoursAbsent,</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT&nbsp;&nbsp;SUM (P.HoursAbsent) - SUM (P.HoursAbsent)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM&nbsp;&nbsp;Presence P<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WHERE&nbsp;&nbsp;(P.EmpID_fk = E.EmpID)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND&nbsp;&nbsp;(P.DateWorked Between @JoinDate AND @CurrentDate)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ) &nbsp;AbsentDifference,</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; E.Age</p> <p>FROM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Employee E</p> <p>INNER JOIN&nbsp;&nbsp;&nbsp;&nbsp; EmployeeStatus ES</p> <p>ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; E.Status_fk = ES.Status_ID</p> <p>INNER JOIN&nbsp;&nbsp;&nbsp;&nbsp; Marital M</p> <p>ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; E.Marital_fk = M.Marital_ID</p> <p>INNER JOIN&nbsp;&nbsp;&nbsp;&nbsp; Presence P</p> <p>ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; E.EmpID = P.EmpID_fk</p> <p>WHERE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(P.DateWorked Between @JoinDate AND @CurrentDate)</p> <p>AND&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (E.Status_fk &gt; 5)</p> <p>ORDER BY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; E.Name, E.Status_fk, E.Marital_fk</p> <p>In the above query, @JoinDate and @CurrentDate are passed in parameters, the above query is working perfectly within sql server 2005 but not with the web-app...</p> <p>Thanks...</p> 2007-08-02T09:52:43-04:001837302http://forums.asp.net/p/1140687/1837302.aspx/1?Re+Web+App+waiting+for+indefinite+timeRe: Web-App waiting for indefinite time <p>Try this</p> <p>Declare @TotalHoursWorked int</p> <p>Declare @TotalHoursAbsent int</p> <p>Declare @AbsentDifference int</p> <p>Set @TotalHoursWorked = (SELECT&nbsp;&nbsp;SUM (P.HoursWorked) FROM&nbsp;&nbsp;Presence P<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE&nbsp;&nbsp;P.EmpID_fk = E.EmpID<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND&nbsp;&nbsp;P.DateWorked Between @JoinDate AND @CurrentDate)</p> <p>Set @TotalHoursAbsent = (SELECT&nbsp;&nbsp;SUM (P.HoursAbsent)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM&nbsp;&nbsp;Presence P<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE&nbsp;&nbsp;P.EmpID_fk = E.EmpID<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND&nbsp;&nbsp;P.DateWorked Between @JoinDate AND @CurrentDate)</p> <p>Set @AbsentDiffrence = (SELECT&nbsp;&nbsp;SUM (P.HoursAbsent) - SUM (P.HoursAbsent)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM&nbsp;&nbsp;Presence P<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WHERE&nbsp;&nbsp;P.EmpID_fk = E.EmpID<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND&nbsp;&nbsp;(P.DateWorked Between @JoinDate AND @CurrentDate)</p> <p>&nbsp;</p> <p>Finally have this select query</p> <p>SELECT &nbsp;&nbsp;E.EmpID, E.Name, E.Status_fk, E.Marital_fk, E.Address, @TotalHoursWorked as TotalHoursWorked, @TotalHoursAbsent as TotalHoursAbsent, @AbsentDiffrence as AbsentDiffrence </p> <p>FROM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Employee E</p> <p>INNER JOIN&nbsp;&nbsp;&nbsp;&nbsp; EmployeeStatus ES</p> <p>ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; E.Status_fk = ES.Status_ID</p> <p>INNER JOIN&nbsp;&nbsp;&nbsp;&nbsp; Marital M</p> <p>ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; E.Marital_fk = M.Marital_ID</p> <p>INNER JOIN&nbsp;&nbsp;&nbsp;&nbsp; Presence P</p> <p>ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; E.EmpID = P.EmpID_fk</p> <p>WHERE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(P.DateWorked Between @JoinDate AND @CurrentDate)</p> <p>AND&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (E.Status_fk &gt; 5)</p> <p>ORDER BY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; E.Name, E.Status_fk, E.Marital_fk</p> <p>&nbsp;</p> <p>Idea is to remove the subqueries in the table.</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> 2007-08-02T11:06:35-04:001839538http://forums.asp.net/p/1140687/1839538.aspx/1?Re+Web+App+waiting+for+indefinite+timeRe: Web-App waiting for indefinite time <p>There might be an issue with your asp.net code. Is it possible for you to paste the code where you are calling this SP?</p> <p>-Vivek</p> 2007-08-03T09:55:22-04:001842299http://forums.asp.net/p/1140687/1842299.aspx/1?Re+Web+App+waiting+for+indefinite+timeRe: Web-App waiting for indefinite time <font face="Times New Roman" size="3"><span style="font-size:10pt; font-family:Verdana"> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">Hi Abhishek,</font></p> <font face="Times New Roman" size="3">&nbsp;</font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">Sorry for late reply and once again thanks for the response. Well actually now the above mentioned query has got a problem. Where we declare our variable @TotalHoursWorked etc for the sub-query, it comes with an error telling that E.EmpID is not recognizable since its not aware of what E is. Its only down in the query where we define E as Employee.</font></p> <font face="Times New Roman" size="3">&nbsp;</font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">Vivik, the code is stright forward and i use it at several places. For your info, its something like:</font></p> <font face="Times New Roman" size="3">&nbsp;</font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">DataSet ds = new DataSet ();</font></p> <font face="Times New Roman" size="3">&nbsp;</font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">SqlConnection conn = Initialize it...</font></p> <font face="Times New Roman" size="3">&nbsp;</font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">SqlCommand<span style="">&nbsp;&nbsp; </span>cmd = new SqlCommand ();</font></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">cmd.CommandType = SqlCommandType.StoredProcedure;</font></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">cmd.CommandText = &quot;sp_MyStoredProcedure&quot;;</font></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">cmd.Parameters.Add (new SqlParameter (&quot;Name1&quot;, Type, Length).Value = parameter1</font></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">cmd.Parameters.Add (new SqlParameter (&quot;Name2&quot;, Type, Length).Value = parameter2</font></p> <font face="Times New Roman" size="3">&nbsp;</font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">SqlDataAdapter da = new SqlDataAdapter (cmd);</font></p> <font face="Times New Roman" size="3">&nbsp;</font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">da.Fill (ds);</font></p> <font face="Times New Roman" size="3">&nbsp;</font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">The above is just stright forward code and requires no explanation. I have used it so many times. Either there is something wrong with the query or something in the whole process is not right...</font></p> <font face="Times New Roman" size="3">&nbsp;</font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">Thanks for your time...</font></p> </span></font> 2007-08-06T03:46:34-04:001842303http://forums.asp.net/p/1140687/1842303.aspx/1?Re+Web+App+waiting+for+indefinite+timeRe: Web-App waiting for indefinite time <p><font face="Times New Roman" size="3"><span style="font-size:10pt; font-family:Verdana">Also I have tested the parameters (which i pass from my application) so many times and they work just fine...</span></font></p> 2007-08-06T03:48:31-04:001842393http://forums.asp.net/p/1140687/1842393.aspx/1?Re+Web+App+waiting+for+indefinite+timeRe: Web-App waiting for indefinite time <p>Hi,</p> <p>I forgot the Employee table join while popluating the variables, include them and the obove query will be fine, try this and i am sure there wont be problem in executing the stored procedure </p> 2007-08-06T05:26:53-04:001842560http://forums.asp.net/p/1140687/1842560.aspx/1?Re+Web+App+waiting+for+indefinite+timeRe: Web-App waiting for indefinite time <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">Hi Abhishek,</font></p> <font face="Times New Roman" size="3">&nbsp;</font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">Well i got the join in the variables but now the problem is that although the result set (number of rows) is correct but the calculated fields are equal for all the employees e.g. for @TotalHoursWorked the SUM is equal for all employees. Let us see at one of the query after editing:</font></p> <font face="Times New Roman" size="3">&nbsp;</font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">Set @TotalHoursWorked = (SELECT<span style="">&nbsp; </span>SUM (P.HoursWorked) FROM<span style="">&nbsp; </span>Presence P</font></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp; </span>INNER JOIN Employee E ON P.EmpID_fk = E.EmpID // newly added join</font></font></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>WHERE<span style="">&nbsp; </span>P.EmpID_fk = E.EmpID</font></font></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>AND<span style="">&nbsp; </span>P.DateWorked Between @JoinDate AND @CurrentDate)</font></font></p> <font face="Times New Roman" size="3">&nbsp;</font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">In the above case, the SUM is being calculated from the entire table. Thus the results returned are euqal for all the employees.</font></p> <font face="Times New Roman" size="3">&nbsp;</font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">What should be done to compute values for individual employees. By the way, i see a dramatic improvement in the result set being returned within SQL Server. From 6 seconds it went to 1 second, cool...</font></p> <font face="Times New Roman" size="3">&nbsp;</font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">Thanks for your patience...</font></p> 2007-08-06T07:08:50-04:001842570http://forums.asp.net/p/1140687/1842570.aspx/1?Re+Web+App+waiting+for+indefinite+timeRe: Web-App waiting for indefinite time <p>use group by on employees</p> 2007-08-06T07:16:53-04:001842602http://forums.asp.net/p/1140687/1842602.aspx/1?Re+Web+App+waiting+for+indefinite+timeRe: Web-App waiting for indefinite time <p>Create 3 table variables for each <font face="Times New Roman" size="3">@TotalHoursWorked etc. having columns EmpID and the TotalHoursWorked and insert like this</font></p> <p><font face="Times New Roman" size="3">Insert into @TotalHoursWorked</font></p> <font face="Times New Roman" size="3">Values(SELECT<span style="">&nbsp;EmpID, </span> SUM (P.HoursWorked) FROM<span style="">&nbsp; </span>Presence P</font><font face="Times New Roman" size="3"> <p class="MsoNormal" style="margin:0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="">&nbsp;&nbsp;&nbsp; </span>INNER JOIN Employee E ON P.EmpID_fk = E.EmpID // newly added join</font></font></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>WHERE<span style="">&nbsp; </span>P.EmpID_fk = E.EmpID</font></font></p> <p class="MsoNormal" style="margin:0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>AND<span style="">&nbsp; </span>P.DateWorked Between @JoinDate AND @CurrentDate </font></font></p> <p class="MsoNormal" style="margin:0in 0in 0pt">group By E.EmpID)</p> <p class="MsoNormal" style="margin:0in 0in 0pt">&nbsp;</p> <p class="MsoNormal" style="margin:0in 0in 0pt">This will give the Employees and thier Sum</p> <p class="MsoNormal" style="margin:0in 0in 0pt">&nbsp;</p> <p class="MsoNormal" style="margin:0in 0in 0pt">and then in the main query you join with these tables on empid to get the result.</p> </font> 2007-08-06T07:38:28-04:001842611http://forums.asp.net/p/1140687/1842611.aspx/1?Re+Web+App+waiting+for+indefinite+timeRe: Web-App waiting for indefinite time <p>Let me give it a try, thanks alot for your help and patience, im obliged...</p> 2007-08-06T07:45:05-04:001844647http://forums.asp.net/p/1140687/1844647.aspx/1?Re+Web+App+waiting+for+indefinite+timeRe: Web-App waiting for indefinite time <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">Hi Abhishek,</font></p> <font face="Times New Roman" size="3">&nbsp;</font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">Awesom, my problem got solved. I used table variables and Joined those tables with my query and that gave me my result with exactly the same Parameters and Where Clause. Also the performance was great. </font><font face="Times New Roman" size="3">I cant believe it. Greate job Abhishek. Really wonder job done. Thumbs upto you and i specially admire your patience in this whole process.</font></p> <font face="Times New Roman" size="3">&nbsp;</font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">I&nbsp;also learnt a wonder technique of writing better queries with SQL Server. I still have my&nbsp;point&nbsp;unanswered&nbsp;as why not the same query (leaving apart the table variables) didnt work at the first place. Can you guess what could be going wrong without the table variables. Also why the application hung indefintely ???</font></p> <font face="Times New Roman" size="3">&nbsp;</font> <p class="MsoNormal" style="margin:0in 0in 0pt"><font face="Times New Roman" size="3">Anyways, once again thanks alot for your time and patience. Wonderful job done man...</font></p> 2007-08-07T08:03:27-04:001844701http://forums.asp.net/p/1140687/1844701.aspx/1?Re+Web+App+waiting+for+indefinite+timeRe: Web-App waiting for indefinite time <p>Thanks for the same By the way u know me I am Abhishek(aptech)</p> 2007-08-07T08:39:05-04:00