Solved

Check if WAN machine is online before connecting

Posted on 2013-11-02
2
364 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 42

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 42

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Choosing a core focus or particular set of features and options can be tough. To help out, we’re going to highlight a handful of things your business needs on one of your social media pages. In other words, if one of these is missing, you should imp…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

632 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