473,509 Members | 2,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to quick-check SQL connection

Hi,

I'm developing an application that runs on laptops that periodically
connect to network. I am collecting data in local tables within the
MDB. I want to recognize the occasional network connection so I can
upload the collected data to SQL server and retrieve updated look-up
information.

This application has 2 linked SQL server tables that are not used until
I find myself connected to the network. Since I have these links, I
figured I could use them with timeout to "guess" my connection status.

So far this works but it takes the default 30 seconds to timeout. I'd
hate to force the user to wait 30 seconds every time they start the
application off-line.

I through together the following code to see if I could alter the
timeout (make it a bit sooner) but it has no effect. Has anybody else
ever done something like this? Is there a better way to detect the
network connection?

' testing with SQL Server shut down
' ---------------------------------------------------------
Dim objRS As New ADODB.Recordset
Dim objCmd As ADODB.Command
Dim conn As ADODB.Connection

' No problem with the following connection block - no timeout
' ---------------------------------------------------------
Set conn = New ADODB.Connection
With conn
.ConnectionString = CurrentProject.BaseConnectionString
.CursorLocation = adUseClient
.CommandTimeout = 10 ' shorten delay to 10 seconds
.Open
End With

' despite the fact that I've set the commandtimeout of the
' connecton to 10 seconds AND I've set the commandtimeout
' of the following ADODB.Command to 10 seconds - the following
' query takes 43 seconds to timeout
' ---------------------------------------------------------
Set objCmd = New ADODB.Command
With objCmd
.CommandType = adCmdText
.CommandText = "SELECT * FROM dbo_MySQLLinkedTable"
.ActiveConnection = conn
.CommandTimeout = 10 ' shorten delay to 10 seconds
Set objCmd = .Execute
End With

Nov 18 '05 #1
7 12758

You haven't set the ConnectionTimeout property of the connection object

ConnectionTimeout: Indicates how long to wait while establishing a
connection before terminating the attempt and generating an error.

As opposed to

CommandTimeout: Indicates how long to wait while executing a command before
terminating the attempt and generating an error.

--
Terry Kreft

"ZRexRider" <je****@ptd.net> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
Hi,

I'm developing an application that runs on laptops that periodically
connect to network. I am collecting data in local tables within the
MDB. I want to recognize the occasional network connection so I can
upload the collected data to SQL server and retrieve updated look-up
information.

This application has 2 linked SQL server tables that are not used until
I find myself connected to the network. Since I have these links, I
figured I could use them with timeout to "guess" my connection status.

So far this works but it takes the default 30 seconds to timeout. I'd
hate to force the user to wait 30 seconds every time they start the
application off-line.

I through together the following code to see if I could alter the
timeout (make it a bit sooner) but it has no effect. Has anybody else
ever done something like this? Is there a better way to detect the
network connection?

' testing with SQL Server shut down
' ---------------------------------------------------------
Dim objRS As New ADODB.Recordset
Dim objCmd As ADODB.Command
Dim conn As ADODB.Connection

' No problem with the following connection block - no timeout
' ---------------------------------------------------------
Set conn = New ADODB.Connection
With conn
.ConnectionString = CurrentProject.BaseConnectionString
.CursorLocation = adUseClient
.CommandTimeout = 10 ' shorten delay to 10 seconds
.Open
End With

' despite the fact that I've set the commandtimeout of the
' connecton to 10 seconds AND I've set the commandtimeout
' of the following ADODB.Command to 10 seconds - the following
' query takes 43 seconds to timeout
' ---------------------------------------------------------
Set objCmd = New ADODB.Command
With objCmd
.CommandType = adCmdText
.CommandText = "SELECT * FROM dbo_MySQLLinkedTable"
.ActiveConnection = conn
.CommandTimeout = 10 ' shorten delay to 10 seconds
Set objCmd = .Execute
End With

Nov 18 '05 #2
Thanks Terry....

Unfortunately it had no effect. My query attempt still takes 43
seconds to time out (odd number huh?) no matter what timeout promperty
I set.

Nov 18 '05 #3
I don't know the API calls, but have you thought about PINGing the server. A
single ping should respond much quicker then 30 sec.

"ZRexRider" <je****@ptd.net> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
Hi,

I'm developing an application that runs on laptops that periodically
connect to network. I am collecting data in local tables within the
MDB. I want to recognize the occasional network connection so I can
upload the collected data to SQL server and retrieve updated look-up
information.

This application has 2 linked SQL server tables that are not used until
I find myself connected to the network. Since I have these links, I
figured I could use them with timeout to "guess" my connection status.

So far this works but it takes the default 30 seconds to timeout. I'd
hate to force the user to wait 30 seconds every time they start the
application off-line.

I through together the following code to see if I could alter the
timeout (make it a bit sooner) but it has no effect. Has anybody else
ever done something like this? Is there a better way to detect the
network connection?

' testing with SQL Server shut down
' ---------------------------------------------------------
Dim objRS As New ADODB.Recordset
Dim objCmd As ADODB.Command
Dim conn As ADODB.Connection

' No problem with the following connection block - no timeout
' ---------------------------------------------------------
Set conn = New ADODB.Connection
With conn
.ConnectionString = CurrentProject.BaseConnectionString
.CursorLocation = adUseClient
.CommandTimeout = 10 ' shorten delay to 10 seconds
.Open
End With

' despite the fact that I've set the commandtimeout of the
' connecton to 10 seconds AND I've set the commandtimeout
' of the following ADODB.Command to 10 seconds - the following
' query takes 43 seconds to timeout
' ---------------------------------------------------------
Set objCmd = New ADODB.Command
With objCmd
.CommandType = adCmdText
.CommandText = "SELECT * FROM dbo_MySQLLinkedTable"
.ActiveConnection = conn
.CommandTimeout = 10 ' shorten delay to 10 seconds
Set objCmd = .Execute
End With

Nov 18 '05 #4
Well I'm guessing your doing something wrong then. The ConnectionTimeout
property is the one to be using/

What value have you set it at?

--
Terry Kreft

"ZRexRider" <je****@ptd.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Thanks Terry....

Unfortunately it had no effect. My query attempt still takes 43
seconds to time out (odd number huh?) no matter what timeout promperty
I set.

Nov 19 '05 #5
Try this:

If Application.CurrentProject.IsConnected Then...

I'm not sure it works with .mdb but it works fine with .adp and it's
wort to give it a try.

ZRexRider wrote:
I'm developing an application that runs on laptops that periodically
connect to network. I am collecting data in local tables within the
MDB. I want to recognize the occasional network connection so I can
upload the collected data to SQL server and retrieve updated look-up
information.
...
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
With conn
.ConnectionString = CurrentProject.BaseConnectionString
.CursorLocation = adUseClient
.CommandTimeout = 10 ' shorten delay to 10 seconds
.Open
End With


Nov 19 '05 #6
And it would be a good guess Terry.

Turns out that I was using the connection of the MDB itself instead of
the connection of the linked table that I intended to query. I would
set my new connection object connection string to that of the MDB, set
the timeout of this connection and then query the linked SQL server
table........ugh.

I am now setting the .ConnectionString to value of the "Connect" field
in the MSysObjects table and THEN trying a query. Now it only takes
whatever amount of time I set in the .ConnectionTimeout .
Thanks for looking at it with me

Nov 21 '05 #7
LOL, easily done, you get your head so stuck into the code and the
technicalities sometimes you forget the data.
--
Terry Kreft

"ZRexRider" <je****@ptd.net> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
And it would be a good guess Terry.

Turns out that I was using the connection of the MDB itself instead of
the connection of the linked table that I intended to query. I would
set my new connection object connection string to that of the MDB, set
the timeout of this connection and then query the linked SQL server
table........ugh.

I am now setting the .ConnectionString to value of the "Connect" field
in the MSysObjects table and THEN trying a query. Now it only takes
whatever amount of time I set in the .ConnectionTimeout .
Thanks for looking at it with me

Nov 21 '05 #8

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

Similar topics

15
2102
by: Ron Adam | last post by:
Does anyone have suggestions on how to improve this further? Cheers, Ron_Adam def getobjs(object, dlist=, lvl=0, maxlevel=1): """ Retrieve a list of sub objects from an object. """
8
5362
by: Dutchy | last post by:
Dear reader, In an attempt to obtain the path to the quick-launch-folder in order to create a shortcut to my application-updates during installation , I thought to: 1- check if quick launch...
0
1431
by: Sean | last post by:
Hi, I am doing a desktop application and now I am having problem preventing the quick highlight of a treenode when a user right clicks a treenode. The reason I am doing this is that only when...
3
2614
by: Martin Dew | last post by:
hi, I want to interogate the Quick Launch folder, looking at each icon and getting the image, and target that it fires when clicked. I can get to the folder and create a filelist of the icons, but...
2
1770
by: A.M | last post by:
Hi, I uderstand any Quick Start samples in .NET documentation or VS.NET documentation or in any other community/portal websites, is a link to http://samples.gotdotnet.com/quickstart/. That...
2
1022
by: Yousri | last post by:
Hi All, Is there any quick reference on how to configure ASP.Net, Visual Studio.Net IIS 5.1 and front Page Server extension so that all work together. I am running XP Professional OS. Thanks...
5
1544
by: David Thielen | last post by:
Hi; Almost all of the Quick Starts show the code in the .aspx file inside a <script> instead of in a seperate .aspx.cs file. My instinct is that the code should be in a seperate file to keep the...
55
2676
by: Steven Nagy | last post by:
Hi all, Sorry I have no time to test this myself.... Can I add the same attribute to a field twice? Eg. Public string myField;
1
4520
by: DILA | last post by:
Hi, I have included an embedded Real Player and an embedded Quick Time Player for streaming videos, in my web pages. I'm interested in searching for a method or a script to disable the...
3
2534
by: homec | last post by:
Hi, I have included an embedded Real Player and an embedded Quick Time Player for streaming videos, in my web pages. I'm interested in searching for a method or a script to disable the ...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.