Technical Article

SQLPing.vbs

,

Troubleshooting intermitten connectivity issues can be difficult. One approach is to repeatedly test connecting to SQL Server outside of an existing application in order to verify if a server-wide intermitten issue is occurring. This script is used to test remote connectivity to a SQL Server. The script loops in one minute intervals (adjust as needed). If a problem connecting to SQL Server occurs an error is written to the Application log on the machine from which the script is executed. The script requires SQL-DMO which is installed with the SQL Server client tools.

' Script:	sqlping.vbs
' Purpose:	Test remote connectivity and log error to Application log if connectivity problems
' Author:	Chad Miller (cmille19@tampabay.rr.com)
' Created:	August 8 2006

On ERROR RESUME NEXT

Do While True
	Wscript.Echo "Connecting..."

	Set oServer = CreateObject("SQLDmo.SqlServer")
	oServer.LoginTimeout = 10
	oServer.LoginSecure = True 
	oServer.Connect "MyServer" ' Change Server Name
	
	IF err.number <> 0 Then 
	' An error connecting has occurred write error to local Application log
	' Note this is not the Application log on the SQL Server, but rather
	' The Application on the machine the script is run from
		Set WshShell = WScript.CreateObject("WScript.Shell")
		strCommand = "eventcreate /T Error /ID 100 /L Application /D " & _
		Chr(34) & "Timeout on MyServer has occurred." & Chr(34) & " /SO " & Chr(34) & "Timeout" & Chr(34) ' Change Server Name
		WshShell.Run strcommand
		Wscript.Echo "Fail"
	else
		Wscript.Echo "Success"
	End If

	oServer.DisConnect 
	Set oServer = Nothing
	' Sleep for 1 minute
	Wscript.Echo "Sleeping..."
	Wscript.Sleep 60000

Loop

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating