SQL Server - Sql Server timeout problem

Asked By David
06-Sep-08 08:52 AM
Hi all,

I am having problems with SQL Server on a clients website...

I know this email is quite long. I really need to sort out the failure
rather than anything else here. I add all other info in case it is relevant.

The site is built with C#. When I open a connection, I always close it. (I
specifically develop this way, and I have since double checked and triple
checked this is happening) I am connecting to a SQL 2K5 database.

Occassionally, I get a timeout whilst querying the DB. It only happens in
certain scenarios and does NOT happen all the time. The query is doing a lot
of summing of fields.

I am watching the task manager at the same time.

When it fails, the task manager for SQL goes to 99%. The mem usage is
something like 169MB. When the page returns with the fail, the cpu usage
drops.

However, when I run the same query inside SQL Management studio, it looks
like the same thing happens, i.e. the memory usage increases. (I have not
yet tried it when the page fails.)

Any ideas or things I can try would be appreciated.



On another note, in .NET, you can close connections, but not datasets,
datatables, DataAdapters or anything. All my SqlDataReaders are also closed
off.



If it is of any help, my query is...

set DateFormat dmy;
select
TK_Timesheet.CostCenter, TK_Timesheet.UserID as Employee,
Surname + ', ' + FirstName as Name,
sum(cast(ExpensesAmount as Money)) as TotalExpenses,
sum(cast(RadiusTimeMiles as int)) as RadiusMiles,
sum(cast(NightRatePayment as Money)) as NightRate
,SUM(DatePart(HOUR, (cast(HoursWorked as DateTime)))*3600+DatePart(MINUTE,
(cast(HoursWorked as DateTime)))*60) / 3600.00  as Hours
, StandingDataChange

from TK_JobDetail
left join TK_Timesheet on TK_JobDetail.TimesheetID =
TK_Timesheet.TimesheetID  and TSID in(select max(TSID) from TK_Timesheet
group by TimesheetID)
left join TK_UserDetail on TK_Timesheet.UserID =
TK_UserDetail.EmployeeNumber

where TK_Timesheet.UserID is not null
and isnull(TK_Timesheet.SupervisorApproved, 0) > 0
and isnull(TK_Timesheet.BMApproved, 0) > 0
and (RowDeleted is null or RowDeleted = '0' or RowDeleted = '')
and ChildRow = 0

and SubmitWeek = @SubmitWeek and SubmitYearPeriod = @SubmitYear

group by

TK_Timesheet.UserID, Surname + ', ' + FirstName
, StandingDataChange
, TK_Timesheet.CostCenter, EmployeeNumber

order by  TK_Timesheet.CostCenter, EmployeeNumber



(On another note, I was having problems with casting the HoursWorked as
DateTime. However, when checking the database, I could not find any invalid
hours. (In this case, they are stored as varchar). However, when I put " AND
isDate(HoursWorked) = 1 " in the where clause, the SQL worked. What is
really odd is that this error only happened when I filtered by having a
costcenter (in the where clause), but across ALL cost centers (no cost
center filter), it worked quite happily (this may be related to the other
problem above). (This is without " or RowDeleted = '' " in the above
statement)

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
SQL Server
(1)
NOT NULL
(1)
Cast
(1)
Database
(1)
Varchar
(1)
  Uri Dimant replied...
07-Sep-08 01:29 AM
David
When you connect to SQL Server what is the value  you specify for timeout? I
think it is time to start looking at  your query  fo optimizing
Run the query with SET STATISTICS IO ON and SET STATISTICS PROFILE ON  and
put  in here ( if you can)


Cooud be above  to re-write as?

and TK_Timesheet.SupervisorApproved IS NOT NULL
and TK_Timesheet.BMApproved  IS NOT NULL




Can you show an example?
  Norman Yuan replied...
07-Sep-08 11:36 AM
When you run a web application against a SQL Server database process, there
are 3 types of timeout:

1. connection timeout: the timeout for application to try to establish
connection the target database, if the connection cannot be created in given
timespan, you get connection timeout;
2. command timeout: in .NET app, the actual data manipulation in database is
called through SqlCommand, which has a default timeout, meaning, when
execution starts, it wait for given timespan for the data manipulation in
database to be completed. If not, then time out
3. website response timeout: a request sends to website, and waits for the
website to process the request do be done within given timespan (default to
120 sec)

It sounds you get command timeout. Firstly, you can extend commad timeout
(default is 30sec, I believe) by set SqlCommand.CommandTimeout property to
longer time. But more importantly, you need to optimize your SQL process.
You only extend Command Timeout when you believe you have done everything to
optimize the SQL process.
Create New Account
help
Problem with DROP CONSTRAINT SQL Server When I issue the following T-SQL 2008: ALTER TABLE ALIS.mc.LOCApp DROP CONSTRAINT LOCApp_Created_df I get the following errors: Msg Object Explorer the message I get is: The Default 'LOCApp_Created_df' does not exist on the server. (SQL Manager UI) What is going on? Patrick = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = Patrick Jackman Vancouver, BC 604-874-5774 SQL Server Programming Discussions DELETED.ConcurrencyID (1) ALIS.mc.LOCApp (1) SQL Server (1) IxLOCTypeID (1) SchemaAuditDDLTrigger (1) LOCTypeID (1) LOCAppID (1) Stored procedure (1) e r
Why_can’t_recursive_queries_contain. . .? SQL Server hi I hope I didn = 92t put too many questions 1) Why can = 92t recursive queries also be unioned together with UNION operator ( instead they must use UNION ALL )? thanx SQL Server Programming Discussions SQL Server 2008 (1) SQL Server 2005 (1) SQL Server 2000 (1) SQL Server (1) Oracle (1) Ruby (1) MichaelcoAToptonlineDOTnet (1
try. . .catch execution issue SQL Server According to BOL unless you physically return in the catch, any code after the "end not execute any code or set the return code of the procedure. This is in SQL Server 2008. There are 5 tables and 5 prodcedures in all. If you email me, I of the DB to see what I am referrring to. Has anyone else expereienced this? SQL Server Programming Discussions SQL Server 2008 R2 (1) SQL Server 2005 (1) SQL Server 2000 (1) SQL Server 2008 (1
Optional IN Clause parameter SQL Server I have a SQL Server 2005 stored procedure that will receive a series of valeus to be passed to an to parse the comma-delimited values into a table object as shown below: DECLARE @DeptNames varchar(max) SET @DeptNames = 'Accounting, Finance' SELECT * FROM Personnel WHERE Department IN CASE WHEN @DeptNames <> '' THEN I am trying to accomplish is to have @DeptNames as an optional parameter. Since this SQL does not work as shown, what must I do in order to accomplish this? I really want to avoid dynamic SQL and since I may have many such optional IN clause parameters, managing multiple versions of the same SQL would become cumbersome. Thanks Carl SQL Server Programming Discussions SQL Server 2008 R2 (1) SQL
Possible server bug, would welcome your views SQL Server Hi all, I have run into a bug and AFAICS it is not me (you may well decide otherwise though). Setup is Win7, 32-big, dual core and sufficient memory, sql server 2008 R2, patched to SP1 (bug appears pre and post patch). select @@version -> Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (Intel X86) Jun 17 2011 00:57:23 where minclassdata <> maxclassdata -> Msg 8114, Level 16, State 5, Line 1 Error converting data type varchar to float. Doesn't like it. Try in two steps instead: select * into #blaggle from