I need to understand how to detect and recover from a network down / server unavailable situation.
i'm reading a db (sound level) meter from a serial port and writing to a local access db on same PC 24x7.
the code below is used to write local data to a SQL server via ODBC and then delete the local data.
Ideas, comments and help appreciated,
Public Sub readnwrite()
Dim dlyloop As Integer
Dim strSQL As String
Dim xfertime
Dim proctime
Dim PauseTime, Start, Finish, TotalTime
PauseTime = 4 ' Set duration.
On Error GoTo whoops
DoCmd.SetWarnings False
proctime = DateAdd("n", 1, Now)
Do While True
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
If proctime < Now Then
proctime = DateAdd("n", 1, Now) ' add a minute for the next slot
xfertime = DateAdd("n", -2, Now) ' - 1 minute use whole minute
Forms!Form1!fxfertime = xfertime
strSQL = "INSERT INTO dbo_dbdata " _
& "( dbdate, dblocation, dbstat, dbleveln )" _
& " SELECT dbdata.dbdate, dbdata.dblocation, " _
& " dbdata.dbstat, dbdata.dbleveln " _
& "FROM dbdata " _
& "WHERE (((dbdata.dbdate)< #" & xfertime & "#));"
DoCmd.RunSQL strSQL ' append dbdata record to dbo_dbdata
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
strSQL = "DELETE dbdata.dbdate, dbdata.*" _
& "FROM dbdata " _
& "WHERE (((dbdata.dbdate)<#" & xfertime & "#));"
DoCmd.RunSQL strSQL ' delete dbdata record
' error catching
'
'
'
'
End If ' full minute
If Forms!Form1!lblStat = "Stopped" Then
DoCmd.SetWarnings False
Exit Do
End If
Loop
Exit Sub
whoops:
MsgBox Err.Description
Resume Next
End Sub
i'm reading a db (sound level) meter from a serial port and writing to a local access db on same PC 24x7.
the code below is used to write local data to a SQL server via ODBC and then delete the local data.
Ideas, comments and help appreciated,
Public Sub readnwrite()
Dim dlyloop As Integer
Dim strSQL As String
Dim xfertime
Dim proctime
Dim PauseTime, Start, Finish, TotalTime
PauseTime = 4 ' Set duration.
On Error GoTo whoops
DoCmd.SetWarnings False
proctime = DateAdd("n", 1, Now)
Do While True
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
If proctime < Now Then
proctime = DateAdd("n", 1, Now) ' add a minute for the next slot
xfertime = DateAdd("n", -2, Now) ' - 1 minute use whole minute
Forms!Form1!fxfertime = xfertime
strSQL = "INSERT INTO dbo_dbdata " _
& "( dbdate, dblocation, dbstat, dbleveln )" _
& " SELECT dbdata.dbdate, dbdata.dblocation, " _
& " dbdata.dbstat, dbdata.dbleveln " _
& "FROM dbdata " _
& "WHERE (((dbdata.dbdate)< #" & xfertime & "#));"
DoCmd.RunSQL strSQL ' append dbdata record to dbo_dbdata
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
strSQL = "DELETE dbdata.dbdate, dbdata.*" _
& "FROM dbdata " _
& "WHERE (((dbdata.dbdate)<#" & xfertime & "#));"
DoCmd.RunSQL strSQL ' delete dbdata record
' error catching
'
'
'
'
End If ' full minute
If Forms!Form1!lblStat = "Stopped" Then
DoCmd.SetWarnings False
Exit Do
End If
Loop
Exit Sub
whoops:
MsgBox Err.Description
Resume Next
End Sub