473,623 Members | 2,693 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.Connectio n

' No problem with the following connection block - no timeout
' ---------------------------------------------------------
Set conn = New ADODB.Connectio n
With conn
.ConnectionStri ng = CurrentProject. BaseConnectionS tring
.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_MySQLLinked Table"
.ActiveConnecti on = conn
.CommandTimeout = 10 ' shorten delay to 10 seconds
Set objCmd = .Execute
End With

Nov 18 '05 #1
7 12789

You haven't set the ConnectionTimeo ut property of the connection object

ConnectionTimeo ut: 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******** *************@g 43g2000cwa.goog legroups.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.Connectio n

' No problem with the following connection block - no timeout
' ---------------------------------------------------------
Set conn = New ADODB.Connectio n
With conn
.ConnectionStri ng = CurrentProject. BaseConnectionS tring
.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_MySQLLinked Table"
.ActiveConnecti on = 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******** *************@g 43g2000cwa.goog legroups.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.Connectio n

' No problem with the following connection block - no timeout
' ---------------------------------------------------------
Set conn = New ADODB.Connectio n
With conn
.ConnectionStri ng = CurrentProject. BaseConnectionS tring
.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_MySQLLinked Table"
.ActiveConnecti on = 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 ConnectionTimeo ut
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.goo glegroups.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.Cur rentProject.IsC onnected 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.Connectio n
Set conn = New ADODB.Connectio n
With conn
.ConnectionStri ng = CurrentProject. BaseConnectionS tring
.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........ug h.

I am now setting the .ConnectionStri ng 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 .ConnectionTime out .
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******** *************@z 14g2000cwz.goog legroups.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........ug h.

I am now setting the .ConnectionStri ng 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 .ConnectionTime out .
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
2117
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
5367
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 is used by the user 2- check if a link to my application is there 3- if so, obtain the path (ANY PATH) to the quick-launch-folder from existing button(s)
0
1436
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 user right clicks exactly within the label of the treenode, that node will get selected, otherwise that node will not get selected.
3
2625
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 cannot seem to find where to go from there, can anyone help ? string dirPath = Path.Combine(System.Environment.GetEnvironmentVariable(Environment.SpecialFolder.ApplicationData),@"Microsoft\Internet Explorer\Quick Launch");
2
1776
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 means if i don't have internet access, i can't have QuickStarts. I am addicted to QuickStarts and i have to do projects is some places with restricted internet access. Can i download the quickstarts in any format, so i will have them ofline or
2
1030
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 for your help in advance. Yousri
5
1549
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 view and the view logic distinct. Is there a strong argument for combining these in one file? (It may just feel wrong to me because of years of J2EE/JSP programming where you always keep them seperate.)
55
2705
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
4530
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 right-click option in the embedded Real & Quick Time players, because I don't want the viewers to download the video but to view it while streaming.
3
2549
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 right-click option in the embedded Real & Quick Time players, because I don't want the viewers to download the video but to view it while streaming.
0
8217
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8160
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8661
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8312
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8460
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4067
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.