Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MOVE ON IF CAN'T CONNECT 1

Status
Not open for further replies.

sshafe

Programmer
Oct 18, 2002
71
US
I'm writing a script to move through a list of SQL Servers. I make a connectivity check on each in the list. My problem now is the error handling. If I cannot connect to the server, I want to write to a log file and move to the next server on the list, but I'm having problems catching the error within the script. "SQL SERVER DOES NOT EXIST OR ACCESS DENIED" 80004005 pops up.
Ideas??

Thanks in advance
;-)
 
Hi
A basic way should be to use the On Error Resume Next statement that allows you to bypass the errors.
But this solutions does not trap any error at all. So you will not be able to log the error.
Perhaps another kind of test to validate your connection.
Something like MapNetworkdrive to the target server (SQL server) and a test on a file which is supposed to exist on the SQL server (the database file for example)...
 
Your error handler logic could log:
Code:
Err.Number
Err.Description
Err.Source
Be sure to call the
Code:
Err.Clear
method in your error handler if you intend to continue processing after errors occur.

It is always good to consult the scripting documentation:



Also look into the ADO
Code:
Errors
collection:


... and the
Code:
Error
object:


This is intended to be part of any ADO error processing logic, but a surprising number of developers just ignore it. Then they complain there isn't any error feedback!

;-)
 
I've done my best to capture the errors, but what I have is not capturing it. I know for a fact that each server on my list exists, so I just need to capture that it could not make a connect and move on

IF ConnectionName2.State <> 0 Then
ConnectionName2.Close ' Kills Database Connection
ConnectionName2.Open(&quot;DSN=&quot; & rsServers.Fields(&quot;sqlservername&quot;))
ELSE
ConnectionName2.Open(&quot;DSN=&quot; & server)
IF connectionname2.State <> 1 Then
LogFile.WriteLine(..............


Thanks again in advance ;-)
 
Hello sshafe,

Try instead...
Code:
if ConnectionName2.errors.count<>0 then
    'display or whatever actions based on .errors(0).number
else
    'some other actions
end if
regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top