Check Internet Connection from NAV

nav_126
Member Posts: 77
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
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
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
0
Comments
-
Try to create a Codeunit with only your code in it.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);
Where you have written this line;
//
if no connenction the system stops here because unable to send. instead of your following code
add this;IF httpreq.status <> 200 THEN;
Then you should call this codeunit in your actual object like for example;IF NOT isInternetConnectionOpen.RUN() THEN ERROR(Text001);
Hope this helps.
Good Luck0 -
To achieve this functionality you can run the code within a Codeunit. This codeunit must be run from another place:
IF NOT CODEUNIT.RUN(CODEUNIT::"Connection Check") THEN BEGIN ErrorText := GETLASTERRORTEXT; CLEARLASTERROR; ... END ELSE ...
0 -
I created a function you can call to see if you can ping the site:
isSiteActive(SiteURL : Text[250]) : Boolean VARS Name DataType Subtype Length wShell Automation 'Windows Script Host Object Model'.WshShell pingFlag Integer WindowStyle Integer WaitForReturn Boolean /VARS CREATE(wShell,TRUE); IF LOWERCASE(COPYSTR(SiteURL,1,7)) = 'http://' THEN SiteURL := COPYSTR(SiteURL,8); IF LOWERCASE(COPYSTR(SiteURL,1,8)) = 'https://' THEN SiteURL := COPYSTR(SiteURL,9); IF STRPOS(SiteURL,'\') <> 0 THEN SiteURL := COPYSTR(SiteURL,1,STRPOS(SiteURL,'\')-1); IF STRPOS(SiteURL,'/') <> 0 THEN SiteURL := COPYSTR(SiteURL,1,STRPOS(SiteURL,'/')-1); WindowStyle := 0; WaitForReturn := TRUE; pingFlag := wShell.Run('ping -n 1 ' + SiteURL,WindowStyle,WaitForReturn); IF pingFlag = 0 THEN EXIT(TRUE); EXIT(FALSE);
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)0 -
Hi Magno,
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 advance0 -
Hi nav_126,
as I told just below my code: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)
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)0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions