Hi,
On a machine where Dynamics NAV 2009 is installed, i want to check if internet connectivity is there or not.
If connectivity is there, system should execute further code else show error and exit.
I searched the forum and found the below code
httpreq is an automation with 'Microsoft WinHTTP Services, version 5.1'.WinHttpRequest
CREATE(httpreq,TRUE);
httpreq.Open('GET','HTTP://www.msn.com');
httpreq.Send;
//-------- if no connenction the system stops here because unable to send.
CLEAR(httpreq);
Now the issue is if connectivity is not there system gives an error as
"The call to member send failed. WinHttp.WinHttpRequest Returned error message".
System does not process any further code but I want to handle this exception through C/AL and give the
customized error message.
If anyone can help on this.
Regards,
NAV Developer
Comments
Where you have written this line;
//
if no connenction the system stops here because unable to send. instead of your following code
add this;
Then you should call this codeunit in your actual object like for example;
Hope this helps.
Good Luck
this should be a good indicator if the internet is on.
But also note, that some servers are not allowing ping (like msn.com, google.com does allow it)
---
My Blog: http://NAV-Magno.be
Tried your suggestion but I am always getting pingflag = 1 even if internet connection is there or not.
Can you please help on this ?
Thanks in advance
as I told just below my code:
It could be that the server you are testing does not allow pinging.
I just did another test here, first i got a pingFlag 0. When I pulled out my network cable I got a 1 as pingFlag.
Maybe you could select http://www.google.com as your ping test?
Another thing could be that you domain does not allow outgoing ping requests (which sometimes happens, but not that much).
You can test if this is the case by using Google (it should always allow ping), so try opening a command window and do ping http://www.google.com to see if you get a result there.
you should see something like:
Pinging http://www.l.google.com [74.125.79.103] with 32 bytes of data:
Reply from 74.125.79.103: bytes=32 time=20ms TTL=53
Reply from 74.125.79.103: bytes=32 time=16ms TTL=53
Reply from 74.125.79.103: bytes=32 time=17ms TTL=53
if you only get a result as following: Request timed out.
that probably means your domain does not allow outgoing ping requests and you will not be able to use this function. (you can always try to convince your network administrator to allow these requests)
---
My Blog: http://NAV-Magno.be