samedi 31 janvier 2015

Application is hanging when database upgraded from SQL Server 2000 to SQL Server 2008 R2


Presently we are working with SQL Server 2000, the database is perfectly working with our software for retail sales counter application developed with VB 6.0. But after upgraded to SQL Server 2008 R2, we are witnessing timeouts. We didn't change code and database structure when we upgraded from 2000 to 2008 R2.


This is the Locking Function for getting max number from table LockFile



Private Function LockDatabase()
Dim cntr As Long
Dim indx As Integer
Dim rec_Lock As New ADODB.Recordset

'On Error GoTo CheckReTry

ReTry:
'Set rec_Lock = db_kshetr.OpenRecordset("select LockSemaphore, BillNo as bno from LockFile", dbOpenDynaset, , 2)
rec_Lock.Open "Select LockSemaphore, BillNo as bno from LockFile", con, adOpenDynamic, adLockPessimistic
TryGetLock:
If rec_Lock.Fields("LockSemaphore") <> gCounter & "Locked" Then
While (rec_Lock.Fields("LockSemaphore") <> "UnLocked")
' For indx = 0 To 10 + Rnd(25)
' Next indx
rec_Lock.Requery
Wend

'rec_Lock.Edit

If rec_Lock.Fields("LockSemaphore") = "UnLocked" Then
rec_Lock.Fields("LockSemaphore") = gCounter & "Locked"
rec_Lock.Update
rec_Lock.Requery
Else
rec_Lock.CancelUpdate
GoTo TryGetLock
End If
End If

While (rec_Lock.Fields("LockSemaphore") <> gCounter & "Locked")
For indx = 0 To 10 + Rnd(25)
Next indx
rec_Lock.Requery
Wend

counter = Val(rec_Lock.Fields("bno") & "")
Set rec_Lock = Nothing
Exit Function
CheckReTry:
MsgBox "Cannot Lock Database", vbCritical + vbOKOnly, "Security"
Exit Function
End Function


This is the UnLocking Function for getting max number from table LockFile



Private Function UnlockDatabase()

Dim cntr As Long
Dim indx As Integer
Dim rec_Lock As New ADODB.Recordset

On Error GoTo CheckReTry

ReTry:
'Set rec_Lock = db_kshetr.OpenRecordset("select LockSemaphore, BillNo as bno from LockFile", dbOpenDynaset, , 2)
rec_Lock.Open "Select LockSemaphore, BillNo as bno from LockFile", con, adOpenDynamic, adLockPessimistic
TryGetLock:
While (rec_Lock.Fields("LockSemaphore") <> gCounter & "Locked")
For indx = 0 To 10 + Rnd(25)
Next indx
rec_Lock.Requery
Wend
'rec_Lock.Edit
rec_Lock.Fields("LockSemaphore") = "UnLocked"
rec_Lock.Update
rec_Lock.Requery

While (rec_Lock.Fields("LockSemaphore") <> "UnLocked")
For indx = 0 To 10 + Rnd(25)
Next indx
rec_Lock.Requery
Wend
Set rec_Lock = Nothing
Exit Function
CheckReTry:
MsgBox "Cannot UnLock Database", vbCritical + vbOKOnly, "Security"
Exit Function
End Function


LockSemaphore Field Stages are Locked and UnLocked


Because we're having multiple clients, if one user locked the Lockfile table and get the maximum BillNo , an another user tries to get maximum BillNo from the same table at the same time, the whole systems will hang including Server(SQL Server 2008 R2).


How can we solve this problem? Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire