473,473 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SQL Server Timeout - Second time in loop

Hi All,

Any help greatly appreciated before I finish pulling the rest of my
hair out.

I'm making a program that allows a user to record their hours. There
are five rows (monday to friday). When a user clicks submit the
programme checks if the row has got user data. If it does it checks if
that day already has data held against it and then does an update or
insert accordingly.

It is all working apart from when the program comes to check the
second day it times out on the command. That command run in query
analyser works fine. The function that carries out the check is

Function CheckInsUpd(ByVal userID As Integer, ByVal inputDate As
String) As Integer
Try

Dim sqlCheckConn As New SqlConnection(strConn)
Dim strcheckSQL As String = "select count(detailID) from
flexiDetail where userID = @uID and flexiDate = @fDate"
sqlCheckConn.Open()
Dim checkCmd1 As New SqlCommand(strcheckSQL, sqlCheckConn)
checkCmd1.Parameters.AddWithValue("@uID", userID)
checkCmd1.Parameters.AddWithValue("@fDate", inputDate)

CheckInsUpd = checkCmd1.ExecuteScalar

sqlCheckConn.Close()

Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function

Any line wrapping is down to the browser...

I'm guessing this is a problem with my program structure as I'm
totally self taught so apologies if this is a noob error. I've scanned
the newsgroups but can't see anything applicable...

Paul
Jun 27 '08 #1
3 1286
Ah... queries worked fine Friday... but not now...

If I query the whole table e.g. select userID from flexidetail then
the query runs almost immediately if I add a where clause then it
takes forever - or at least I've given up after a minute.

I guess I need to repost in a SQL group.

Jun 27 '08 #2
On 21 Apr, 10:37, Panda <paul.dam...@gmail.comwrote:
Ah... queries worked fine Friday... but not now...

If I query the whole table e.g. select userID from flexidetail then
the query runs almost immediately if I add a where clause then it
takes forever - or at least I've given up after a minute.

I guess I need to repost in a SQL group.
And in putting together my post on a SQL group I've spotted that the
program is blocking resource on the SQL Server. Thought I'd put my
program flow here while I test...

Main body runs

Dim sqlAddConn As New SqlConnection(strConn)
Dim sqlCheckResponse As Integer
Dim sqlTrans As SqlTransaction

Try

sqlAddConn.Open()
sqlTrans = sqlAddConn.BeginTransaction()

If (amArr1.Value <"01-01-1900 08:00:00" Or amDep1.Value
<"01-01-1900 00:00:00") Or (pmArr1.Value <"01-01-1900 00:00:00"
And pmDep1.Value <"01-01-1900 00:00:00") Then
'monday
sqlCheckResponse = flexi_actions.CheckInsUpd(userID,
txtDate1.Text)
If sqlCheckResponse = 0 Then
Dim sqlMonday As New SqlCommand
sqlMonday = sqlAddConn.CreateCommand
sqlMonday.CommandText = strInsertSQL
sqlMonday.Parameters.AddWithValue("@uID", userID)
sqlMonday.Parameters.AddWithValue("@fDate",
txtDate1.Text)
sqlMonday.Parameters.AddWithValue("@amA",
amArr1.Value)
sqlMonday.Parameters.AddWithValue("@amD",
amDep1.Value)
sqlMonday.Parameters.AddWithValue("@pmA",
pmArr1.Value)
sqlMonday.Parameters.AddWithValue("@pmD",
pmDep1.Value)
sqlMonday.Parameters.AddWithValue("@extra",
txtExtra1.Text)
sqlMonday.Parameters.AddWithValue("@extraR",
txtExtraRsn1.Text)
sqlMonday.Transaction = sqlTrans
sqlMonday.ExecuteNonQuery()
ElseIf sqlCheckResponse = 1 Then
Dim sqlMonday As New SqlCommand
sqlMonday = sqlAddConn.CreateCommand
sqlMonday.CommandText = strUpdateSQL
sqlMonday.Parameters.AddWithValue("@uID", userID)
sqlMonday.Parameters.AddWithValue("@fDate",
txtDate1.Text)
sqlMonday.Parameters.AddWithValue("@amA",
amArr1.Value)
sqlMonday.Parameters.AddWithValue("@amD",
amDep1.Value)
sqlMonday.Parameters.AddWithValue("@pmA",
pmArr1.Value)
sqlMonday.Parameters.AddWithValue("@pmD",
pmDep1.Value)
sqlMonday.Parameters.AddWithValue("@extra",
txtExtra1.Text)
sqlMonday.Parameters.AddWithValue("@extraR",
txtExtraRsn1.Text)
sqlMonday.Transaction = sqlTrans
sqlMonday.ExecuteNonQuery()
Else
MsgBox("more than 1 result when putting Monday
flexi details!")
End If

End If
sqlCheckResponse = 2 ' to make sure we don't use the last
value
If (amArr2.Value <"01-01-1900 08:00:00" Or amDep2.Value
<"01-01-1900 00:00:00") Or (pmArr2.Value <"01-01-1900 00:00:00"
And pmDep2.Value <"01-01-1900 00:00:00") Then
'Tuesday

sqlCheckResponse = flexi_actions.CheckInsUpd(userID,
txtDate2.Text)
If sqlCheckResponse = 0 Then
Dim sqlTuesday As New SqlCommand
sqlTuesday = sqlAddConn.CreateCommand
sqlTuesday.CommandText = strInsertSQL
sqlTuesday.Parameters.AddWithValue("@uID", userID)
sqlTuesday.Parameters.AddWithValue("@fDate",
txtDate2.Text)
sqlTuesday.Parameters.AddWithValue("@amA",
amArr2.Value)
sqlTuesday.Parameters.AddWithValue("@amD",
amDep2.Value)
sqlTuesday.Parameters.AddWithValue("@pmA",
pmArr2.Value)
sqlTuesday.Parameters.AddWithValue("@pmD",
pmDep2.Value)
sqlTuesday.Parameters.AddWithValue("@extra",
txtExtra2.Text)
sqlTuesday.Parameters.AddWithValue("@extraR",
txtExtraRsn2.Text)
sqlTuesday.Transaction = sqlTrans
sqlTuesday.ExecuteNonQuery()
ElseIf sqlCheckResponse = 1 Then

etc etc for 5 days

the function called is as above...

I'll start to Google and test now but any advice appreciated.
Jun 27 '08 #3
While I'm not entirely sure what your problem is or will end up being,
but I would attempt to open a singular connection and use it to query
within a loop. I see in this method that you're opening the
connection every time it starts, this is fine for a single usage but
for a loop it could become very taxing on the server. Normally the
code I write has a single Connection for every query and then when I'm
done close it out.

Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bryan | last post by:
I'm looking for a definitive answer to a Server.ScriptTimeout question. if I add <% Server.ScriptTimeout = 300 %> to a page, does that then alter the default 90 second script timeout for ALL...
3
by: David Morgan | last post by:
Hello In my ASP page I am trying to ascertain whether a randomly generated ID starts with certain characters that are not allowed or has been used before. When the SQL statement for latter is...
3
by: Hasan | last post by:
Hi I'm having a problem with deadlocks in a table in SQL server when trying to update it through Biztalk 2004. There is no problem when I use the same Biztalk solution to update a similar dummy...
15
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do...
4
by: jas | last post by:
I have a basic client/server socket situation setup....where the server accepts a connection and then waits for commands. On the client side, I create a socket, connect to the server...then I...
7
by: Pietje de kort | last post by:
Hello all, I am trying to build a class that does something, and may timeout while doing so. Ofcouse I want to be a bit elegant, so I came up with the code found below. Problem is, I can't catch...
8
by: BBC1009 | last post by:
I have an application connected to an overseas sql-server using port 1433. But recently it always timeout the connection. Any solution to avoid this??? I am using the VB.net Windowed Form with...
25
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
I tried: <sessionState timeout="1"> </sessionState> bounced IIS, and after 1 minute still had a session. ??? -- thanks - dave
4
by: rowan | last post by:
I'm writing a driver in Python for an old fashioned piece of serial equipment. Currently I'm using the USPP serial module. From what I can see all the serial modules seem to set the timeout when...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.