Check if web server is up when checking for updates

Blake81

Well-known member
Joined
Feb 23, 2006
Messages
304
Location
Georgia, USA
Programming Experience
1-3
I have my application set to check my website for updates, but I don't always have my website up and running. I don't really want the users seeing an error if my site is down. Is there a way to put something in the code for it to check if the site is up, and if it isn't to just run the application without checking?
 
Hi Blake,

i always use this function. It was written for vb 2003 but I never tried it on vs 2005.

Regards
MJCM

VB.NET:
Imports System.Net
Imports System.Net.WebRequest
Imports System.Net.WebResponse
 
#Region " Is Connection Available"
 
Public Function IsConnectionAvailable() As Boolean
' Returns True if connection is available
 
Dim objUrl As New System.Uri("http://blakenet.myftp.org/")
' Setup WebRequest
Dim objWebReq As System.Net.WebRequest
objWebReq = System.Net.WebRequest.Create(objUrl)
Dim objResp As System.Net.WebResponse
Try
' Attempt to get response and return True
objResp = objWebReq.GetResponse
objResp.Close()
objWebReq = Nothing
Return True
Catch ex As Exception
' Error, exit and return False
If objResp Is Nothing Then
Else
objResp.Close()
objResp = Nothing
End If
objWebReq = Nothing
Return False
Finally
If Not objResp Is Nothing Then objResp.Close()
If Not objResp Is Nothing Then objResp = Nothing
End Try
End Function
#End Region
 
Last edited by a moderator:
blake.. just run your code in the debugger with your website DOWN. Catch the point where it crashes, and add some exception handling to that area! :)

See MJCM code for example of Try Catch if you never used it before...
 
Back
Top