Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Pete Sass
  Where is Pete Sass?
 Marathon, Ontario
 Pete Sass
 To: JLW Smith
  Where is JLW Smith?
 United Kingdom
 JLW Smith
Subject: RE: NetworkConnection
Thread ID: 395395 Message ID: 395411 # Views: 53 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Network and Computer Management
Date: Tuesday, January 14, 2014 6:43:17 PM         

> I'm after some code or example which will allow me to bindevent with a network connection state change, for example, somebody pulling out the network lead.
> I've seen numerous examples of scripts to check the current connected state, but a temporary loss may only be very quick, this would be no good. Are there any samples or anybody used something like this?
> If necessary some freeware I could run the background might also be helpful.
> Thanks

I am not sure exactly how sensitive the verification is you need,
but you could consider the following code example.

* --- HasConnection.prg
DECLARE INTEGER IsNetworkAlive IN sensapi INTEGER @lpdwFlags
DECLARE INTEGER GetLastError IN kernel32
LOCAL lnMode
lnMode = 0
IF IsNetworkAlive(@lnMode) = 0
= MESSAGEBOX("This computer currently does not have any LAN/Network connections available.  Check to see if the ;
network cable is unplugged and it's condition.  Verify the status of the network drivers and ensure the NIC card ;
is enabled!",0+64,"There is NO Connection")
= MESSAGEBOX("This computer currently has an active LAN/Network connection.  This does not check to verify if you ;
have Internet access, just verifies if a working and an active network connection exists on this computer!",0+64,"There is a Connection")

You can appreciate from the above code example how I could remove the message boxes and add in what
code logic or behavior I want.

As well, I would generally add a timer into the _screen and set the timer to fire off at a regular
interval depending upon how you setup for code logic in other routine.
In my case instead of the message boxes I have added as well a _screen property and it is set to
.T. if the code shows a connection and .F. if it shows a no connection status.

The in any activities in my forms I can perform a check against the _screen property when-ever I
try to perform something like adding, editing or deleting a records say from a centralized server
within my LAN or for that matter in a WAN.

Keep in mind my SQLEXEC() calls are also error trapped so if I loose a connection during a routine
I get the error number and error message back and a return statement follows this up.

Make sure batch updates, additions and deletions are all wrapped inside a transaction. Do I use
transaction for say a 1 table SQL Update, well in a multiple update scenario, YES!

Hope this information assists you in how another developer handles this stuff.

Pete "the IceMan", from the Great White North of Canada.


NetworkConnection Posted by JLW Smith @ 1/14/2014 5:01:32 PM
RE: NetworkConnection Posted by David Mustakim @ 1/14/2014 5:31:56 PM
RE: NetworkConnection Posted by Pete Sass @ 1/14/2014 6:43:17 PM
RE: NetworkConnection Posted by JLW Smith @ 1/16/2014 10:23:56 AM