473,325 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Testing Internet connection before performing database connections

Hello,

Is there a way to test that an internet connection exists and that you are
able to see the webserver before performing any connections? The reason
being, when I try to connect to an SQL database it takes sooo long to time
out if the connection isn't available. If a user is on a dial up
connection, I'd like to be able to determine that quickly, then ask the user
if they would like to connect for current information otherwise rely on the
local (and possibly outdated) resources.

Any help would be appreciated.

Thanks!
Nov 13 '05 #1
8 3267
Jozef wrote:
Hello,

Is there a way to test that an internet connection exists and that you are
able to see the webserver before performing any connections? The reason
being, when I try to connect to an SQL database it takes sooo long to time
out if the connection isn't available. If a user is on a dial up
connection, I'd like to be able to determine that quickly, then ask the user
if they would like to connect for current information otherwise rely on the
local (and possibly outdated) resources.

Any help would be appreciated.

Thanks!

I don't know if the function at
http://www.mvps.org/access/api/api0067.htm will help. I ran this IP
(www.pcpitstop.com) and it returned the following

? fGetHostName("64.29.201.21")
port-64-1952021-da120383www002.devices.datareturn.com

Determining the network connection (is the user using dial-up or
broadband)...I suppose there's an API somewhere.
Nov 13 '05 #2
This is ancient code. It may or may not do not do what you need to be
done; you could test it and see.

Private Declare Function InternetOpen Lib "wininet.dll" Alias
"InternetOpenA" _
(ByVal strAgent As String, ByVal lngAccessType As Long, _
ByVal strProxyName As String, ByVal strProxyBypass As String, _
ByVal lngFlags As Long) As Long

Private Declare Function InternetCloseHandle Lib "wininet.dll" _
(ByVal hInet As Long) As Integer

Private Const INTERNET_OPEN_TYPE_DIRECT As Long = 1

Public Function CanConnect() As Boolean
Dim mHInternet As Long
mHInternet = InternetOpen("Microsoft Access",
INTERNET_OPEN_TYPE_DIRECT, _
vbNullString, vbNullString, 0)
If mHInternet = 0 Then
MsgBox "Could not open Internet Connection", vbCritical,
"Whatever Caption you Want"
Else
CanConnect = True
InternetCloseHandle mHInternet
End If
End Function

Sub test()
MsgBox CanConnect
End Sub

Nov 13 '05 #3
Salad <oi*@vinegar.com> wrote in
news:NU*****************@newsread3.news.pas.earthl ink.net:
Jozef wrote:
Hello,

Is there a way to test that an internet connection exists and
that you are able to see the webserver before performing any
connections? The reason being, when I try to connect to an SQL
database it takes sooo long to time out if the connection isn't
available. If a user is on a dial up connection, I'd like to be
able to determine that quickly, then ask the user if they would
like to connect for current information otherwise rely on the
local (and possibly outdated) resources.

Any help would be appreciated.

Thanks!

I don't know if the function at
http://www.mvps.org/access/api/api0067.htm will help. I ran this
IP (www.pcpitstop.com) and it returned the following

? fGetHostName("64.29.201.21")
port-64-1952021-da120383www002.devices.datareturn.com

Determining the network connection (is the user using dial-up or
broadband)...I suppose there's an API somewhere.


While that is interesting and useful code, it won't tell you if
you're connected to the Internet. All it tells you is if there is
DNS information to answer the question, which could be cached
locally, or could be hard-wired in a HOSTS file.

Try this:

Go to the System32 directory, browse to \Drivers\Etc and open HOSTS.
Add an entry like this:

192.168.1.123 BogusMachine

Then try your code for both the IP address and the machine name. It
will resolve even if you're not connected to the Internet.

Now, find a machine on the Internet and enter it's IP address and
name in HOSTS. Disconnect from the Internet and run the code. You'll
see that it will return results.

So, this code is not a good proxy for answering the question "am I
connected to the Internet?"

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #4
"ly******@yahoo.ca" <ly******@yahoo.ca> wrote in
news:11**********************@g43g2000cwa.googlegr oups.com:
This is ancient code. It may or may not do not do what you need to
be done; you could test it and see.

Private Declare Function InternetOpen Lib "wininet.dll" Alias
"InternetOpenA" _
(ByVal strAgent As String, ByVal lngAccessType As Long, _
ByVal strProxyName As String, ByVal strProxyBypass As
String, _ ByVal lngFlags As Long) As Long

Private Declare Function InternetCloseHandle Lib "wininet.dll" _
(ByVal hInet As Long) As Integer

Private Const INTERNET_OPEN_TYPE_DIRECT As Long = 1

Public Function CanConnect() As Boolean
Dim mHInternet As Long
mHInternet = InternetOpen("Microsoft Access",
INTERNET_OPEN_TYPE_DIRECT, _
vbNullString, vbNullString, 0)
If mHInternet = 0 Then
MsgBox "Could not open Internet Connection", vbCritical,
"Whatever Caption you Want"
Else
CanConnect = True
InternetCloseHandle mHInternet
End If
End Function

Sub test()
MsgBox CanConnect
End Sub


I'm not sure I understand what this code does. Does it test that you
have an Internet connection, or only that you've got a TCP/IP
network connection?

I also wonder what's actually doing the testing, as a firewall
(hardware or software) could prevent the test from succeeding even
when the Internet were accessible via explicitly allowed methods.

In the end, I don't think any of the two suggestions is a proper way
to approach the problem, which is not really "am I connected to the
Internet?" but "can I connect to a particular machine?"

That can really only be done by initiating some kind of connection
to the remote machine or by pinging it to see if it's available. I
don't know what the best method for doing that from Access would be,
but it seems to me that you want to do a test that answers the
actual question that is the problem you're trying to address.

And, heaven forfend, Lyle, but you of all people shouldn't be
posting old rusty code that's several years old, don't you think?
You keep telling all of us that about our own tried-and-true methods
for coding in Access.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #5
ly******@yahoo.ca wrote:
This is ancient code. It may or may not do not do what you need to be
done; you could test it and see.

Private Declare Function InternetOpen Lib "wininet.dll" Alias
"InternetOpenA" _
(ByVal strAgent As String, ByVal lngAccessType As Long, _
ByVal strProxyName As String, ByVal strProxyBypass As String, _
ByVal lngFlags As Long) As Long

Private Declare Function InternetCloseHandle Lib "wininet.dll" _
(ByVal hInet As Long) As Integer

Private Const INTERNET_OPEN_TYPE_DIRECT As Long = 1

Public Function CanConnect() As Boolean
Dim mHInternet As Long
mHInternet = InternetOpen("Microsoft Access",
INTERNET_OPEN_TYPE_DIRECT, _
vbNullString, vbNullString, 0)
If mHInternet = 0 Then
MsgBox "Could not open Internet Connection", vbCritical,
"Whatever Caption you Want"
Else
CanConnect = True
InternetCloseHandle mHInternet
End If
End Function

Sub test()
MsgBox CanConnect
End Sub


An addition to Lyle's comments.

The use of the INTERNET_OPEN_TYPE_DIRECT option will work with an "unrestricted" Internet
connection. Using the INTERNET_OPEN_TYPE_PRECONFIG is probably a better choice since it
will try to determine proxy info from the registry.

There may also be installations where an authenticating proxy is used and the use of the
INTERNET_OPEN_TYPE_PROXY is required with values set by the InternetSetOption() call for
these constants:

Public Const INTERNET_OPTION_PROXY_USERNAME = 43
Public Const INTERNET_OPTION_PROXY_PASSWORD = 44

Google's your friend.

--
'---------------
'John Mishefske
'---------------
Nov 13 '05 #6

You'll need to _ask_ the user if it's ok. You can ask them if they
never want to see the message again, but ask first. If nothing else,
it's the nice thing to do.

Then you can ping the server. On some machines this will automatically
cause the dial up to appear, on others not, but in either case if you
get back a vaild ping, you'll know they are connected.

Jozef wrote:
Is there a way to test that an internet connection exists and that you are
able to see the webserver before performing any connections? The reason
being, when I try to connect to an SQL database it takes sooo long to time
out if the connection isn't available. If a user is on a dial up
connection, I'd like to be able to determine that quickly, then ask the user
if they would like to connect for current information otherwise rely on the
local (and possibly outdated) resources.
Any help would be appreciated.


Nov 13 '05 #7
"Chuck Grimsby" <c.*******@worldnet.att.net> wrote in
news:11*********************@g49g2000cwa.googlegro ups.com:
You'll need to _ask_ the user if it's ok. You can ask them if
they never want to see the message again, but ask first. If
nothing else, it's the nice thing to do.

Then you can ping the server. On some machines this will
automatically cause the dial up to appear, on others not, but in
either case if you get back a vaild ping, you'll know they are
connected.


And, of course, even after that, the connection attempt could still
time out if there's something wrong on the SQL Server's end of
things.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #8
David W. Fenton wrote:
Salad <oi*@vinegar.com> wrote in
news:NU*****************@newsread3.news.pas.earthl ink.net:

Jozef wrote:
Hello,

Is there a way to test that an internet connection exists and
that you are able to see the webserver before performing any
connections? The reason being, when I try to connect to an SQL
database it takes sooo long to time out if the connection isn't
available. If a user is on a dial up connection, I'd like to be
able to determine that quickly, then ask the user if they would
like to connect for current information otherwise rely on the
local (and possibly outdated) resources.

Any help would be appreciated.

Thanks!


I don't know if the function at
http://www.mvps.org/access/api/api0067.htm will help. I ran this
IP (www.pcpitstop.com) and it returned the following

? fGetHostName("64.29.201.21")
port-64-1952021-da120383www002.devices.datareturn.com

Determining the network connection (is the user using dial-up or
broadband)...I suppose there's an API somewhere.

While that is interesting and useful code, it won't tell you if
you're connected to the Internet. All it tells you is if there is
DNS information to answer the question, which could be cached
locally, or could be hard-wired in a HOSTS file.

Try this:

Go to the System32 directory, browse to \Drivers\Etc and open HOSTS.
Add an entry like this:

192.168.1.123 BogusMachine

Then try your code for both the IP address and the machine name. It
will resolve even if you're not connected to the Internet.

Now, find a machine on the Internet and enter it's IP address and
name in HOSTS. Disconnect from the Internet and run the code. You'll
see that it will return results.

So, this code is not a good proxy for answering the question "am I
connected to the Internet?"

I was unsure whether or not the code would be of use. I'm glad others
are had some input.

In one of my applications, I check for the existence of the classname of
the email application. If it is not open, I don't allow the sending of
the email unless it's open.
Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Atif Jalal | last post by:
How can I share the sane databse connection between asp.net pages. I also use objects(middleware), so can I pass the same DB connection when I instantiate the object by calling its constructor?
3
by: Jon Booth | last post by:
I have just started programming .NET having come from ASP. We used to create a connection and store it in a session.This meant for each user logging into the site there was only one connection ...
5
by: Brian Kitt | last post by:
I wanted to post this on the SQL newsgroup, but I get a 'page not found' when trying to go to that newsgroup. Since it is a C# app, I'll try it here. I have a C# web application (.NET 1.1). I...
3
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database...
35
by: Terry Jolly | last post by:
Web Solution Goal: Have a global database connection Why: (There will be 30+ tables, represented by 30+ classes) I only want to reference the database connection once. I put the connection...
8
by: Ike | last post by:
Is anyone aware of a means of connection pooling (to MySQL, say) in php? Thanks, Ike
3
by: emrahayanoglu | last post by:
Hello Everyone, I have question about efficient usage of connecting to mysql. Now, i'm using 6 or 7 queries in a page with ajax. In Addition to that, i open connection to mysql for every query....
8
by: mouac01 | last post by:
I'm not sure if this is possible. I would like to have a PHP app on the Internet connect and write to a local database (Intranet). For example, users would go to a web site...
1
by: sherifbk | last post by:
Problem description ============== - I have 4 clients and 1 server (SQL server) - 3 clients are Monitoring console 1 client is operation console - Monitoring console collects some data from...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.