Solved

Check if WAN machine is online before connecting

Posted on 2013-11-02
2
358 Views
Last Modified: 2013-11-04
Hi Expert
I use the following code to connect to a server on WAN using ipaddress.

lcStr = "Driver={SQL SERVER};Server=&SERVERIP;Database=Auto;UID=myname;pwd=mypass;Trusted_Connection=no;"
lnHandle = Sqlstringconnect(lcStr)
If lnHandle>=1
      lnResult = SQLExec(lnHandle, "SELECT * FROM loged ", "cOutData2")
endif

it works fine,but if the server is off line it takes a long time to come back.

Is there any way I can check this ipaddress machine is online before trying to get the information?
Thanks
0
Comment
Question by:b001
  • 2
2 Comments
 
LVL 41

Expert Comment

by:pcelba
ID: 39618950
You may use following code (source: www.News2news.com):
DO declare
 
LOCAL nDst, nHop, nRTT
nDst = inet_addr("217.198.114.255")  && celba.cz
 
STORE 0 TO nHop, nRTT
 
IF GetRTTAndHopCount(nDst, @nHop, 50, @nRTT) <> 0
    ? "Hop count to the destination:", nHop
    ? "Round-trip time, in milliseconds:", nRTT
ELSE
* on error, GetLastError may still return zero
    ? "Error"
ENDIF
* end of main
 
PROCEDURE declare
    DECLARE INTEGER GetRTTAndHopCount IN Iphlpapi;
        INTEGER DestIpAddress, LONG @HopCount,;
        INTEGER MaxHops, LONG @RTT
 
    DECLARE INTEGER inet_addr IN ws2_32 STRING cp

Open in new window

but it also takes time when you are not connected...
0
 
LVL 41

Accepted Solution

by:
pcelba earned 500 total points
ID: 39618971
This seems to be faster (WMI has not so long timeout):
oWMI = getobject("winmgmts:")
cAddress = "127.0.0.1" && Or host name

oPings = oWMI.ExecQuery([Select * from WIN32_Pingstatus where address='] + cAddress + ['])

for each oPing in oPings
  ? oPing.ProtocolAddress
  IF oPing.statuscode = 0
    ?? " Connected"
  ELSE
    ?? " Not accessible"
  ENDIF
NEXT

Open in new window


Source: http://www.foxite.com/archives/network-or-ip-address-status-0000115274.htm
This page also lists many possible Status codes so you may inform user what's possibly wrong.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Read about the ways of improving workplace communication.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question