Hello all,
I have a database with more than 100,000 rows and adding up everyday.
I have a query that is looping every second to check whether a row had been added to the table or not.
if it finds that a record is added then it plays a sound file to alert the user that a record has been added by someone over the network.
Now this makes the server quite slow not only the server, it even slows down the application itself.
This is my exact code. Nothing wrong with it, but can i make it better or is there a workaround.
Any help will be appreciated.Code:Public Sub TestTimer() On Error GoTo HALT Dim Start Dim Check Dim TimeCnt As Double Start = Timer Do Until Check >= Start + 0.005 Check = Timer SqlOrder = "select top(200) OrderNo,CustomerName,UserName,Processed,Time from tblorders order by orderno desc" Set OrderRS = cn.Execute(SqlOrder) With OrderRS If OrderRS.RecordCount > 1 Then CurrentOrder = !OrderNo If CurrentOrder >= NextOrder Then SqlOrder = "select OrderNo,CustomerName,UserName,Processed,Time,COUNT(orderid) as Items from tblorders where (date between'" & OrderDateFrom & " " & "00:00:00" & "' and '" & OrderDateTo & " " & "00:00:00" & "' and username like '%" & cmbUsers.Text & "%') and (partno like '%" & txtSearch.Text & "%' or " & _ " description like '%" & txtSearch.Text & "%' or brand like '%" & txtSearch.Text & "%' or customername like '%" & txtSearch.Text & "%')" & _ " group by orderNo,CustomerName,username,Processed,Time" & _ " order by orderno desc" Set OrderRS = cn.Execute(SqlOrder) iGrid1.FillFromRS OrderRS If CurrentUser = "shabani" Then wmp.URL = "C:\alarm.mp3" End If End If NextOrder = CurrentOrder + 1 Else End If End With Label4.Caption = CurrentOrder Label5.Caption = NextOrder SqlOrder = "Select orderno from tblorders where (date between'" & OrderDateFrom & " " & "00:00:00" & "' and '" & OrderDateTo & " " & "00:00:00" & "' and username like '%" & cmbUsers.Text & "%') and (partno like '%" & txtSearch.Text & "%' or " & _ " description like '%" & txtSearch.Text & "%' or brand like '%" & txtSearch.Text & "%' or customername like '%" & txtSearch.Text & "%')" & _ " group by orderno" Set OrderRS = cn.Execute(SqlOrder) Label1.Caption = "Total Orders - " & OrderRS.RecordCount Me.Caption = "Orders Main Shop : " & OrderDateFrom & " - " & OrderDateTo Me.lblTime.Caption = Check Exit Sub HALT: Loop End Sub




Reply With Quote
