I have a VBS script that I have scheduled to run every 30 minutes, between
5AM and 11PM. The problem I am having is if the internet connection is down
(it is being worked on, so it happens a fair amount), then the script fails
and then doesn't run again until after the server is restarted (which is
next to never). How can I build my script to fail gracefully, and keep
running even if the internet is down?
Here is my script,
'Script for downloading NOAA weather XML data and inserting it into DB
'Start downloading file
sSource = "http://www.weather.gov/data/current_obs/KHLX.xml"
sDest = "\\SWVTC06\inetpub\intranet\rss\weather.xml"
set oHTTP = WScript.CreateObject("Microsoft.XMLHTTP")
set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
oHTTP.open "GET", sSource, False
oHTTP.send
body8209 = oHTTP.responseBody
set oHTTP = nothing
sOut = ""
For i = 0 to UBound(body8209)
sOut = sOut & chrw(ascw(chr(ascb(midb(body8209,i+1,1)))))
Next
set oTS = oFSO.CreateTextFile(sDest, True)
oTS.Write sOut
oTS.Close
set oTS = Nothing
set oFSO = Nothing
'Done downloading file
'Start inserting file into DB
'Parse XML and set variables
Dim mydoc
Set mydoc = WScript.CreateObject("Microsoft.XMLDOM")
mydoc.async=false
mydoc.load("\\swvtc06\inetpub\intranet\rss\weather.xml")
If mydoc.parseError.errorcode<>0 then
MsgBox(mydoc.parseError.errorcode & "<br>")
MsgBox(mydoc.parseError.reason & "<br>")
MsgBox(mydoc.parseError.srcText & "<br>")
MsgBox(mydoc.parseError.URL & "<br>")
Else
dim
wTime,wWeather,wTemp,wHumidity,wWindString,wWindDir,wWindDegrees,wWindMPH,wWindGust
dim wPressure,wDewpoint,wHeatIndex,wWindChill,wVisibility,wPic,wInsertTime
Set objLst = mydoc.getElementsByTagName("*")
wTime = objLst.item(13).childNodes(0).text
wWeather = objLst.item(15).childNodes(0).text
wTemp = objLst.item(16).childNodes(0).text
wHumidity = objLst.item(19).childNodes(0).text
wWindString = objLst.item(20).childNodes(0).text
wPressure = objLst.item(27).childNodes(0).text
wDewpoint = objLst.item(28).childNodes(0).text
wHeatIndex = objLst.item(31).childNodes(0).text
wWindChill = objLst.item(34).childNodes(0).text
wVisibility = objLst.item(37).childNodes(0).text
wPic = objLst.item(39).childNodes(0).text
wInsertTime = Now
End If
dim Conn
dim strSQL
set Conn = CreateObject ("ADODB.connection")
Conn.Open "driver={SQL Server};server=swvtc06;Trusted_Connection=Yes;Initial
Catalog=Weather"
strSQL = "INSERT INTO
Weather(Weather,Temperature,RelativeHumidity,WindString,Pressure,Dewpoint,HeatIndex,WindChill,Visibility,Icon,ObsTime,InsTime)
VALUES ('" & wWeather & "','" & wTemp & "','" & wHumidity & "','" &
wWindString & "','" & wPressure & "','" & wDewpoint & "','" & wHeatIndex &
"','" & wWindChill & "','" & wVisibility & "','" & wPic & "','" & wTime &
"','" & wInsertTime & "')"
'MsgBox strSQL
objRS = Conn.Execute(strSQL)
Thanks,
Drew