Solved

Database connectivity

Posted on 2002-03-14
13
128 Views
Last Modified: 2010-05-02
I have a VB application that connects to a database.  I would like to have this app display connectivity to that database/machine based on a tiered level -just like stoplights (red -- bad, yellow -- ok, green -- good).  How to go about this is up in the air.  Should I run a query and time the query, and find acceptable ranges? Should I ping the machine and base it on response times?  I'm sure other people have done this before, and I'm wondering what they found to be the best practice.

Thanks,
0
Comment
Question by:srobia
  • 6
  • 5
  • 2
13 Comments
 
LVL 4

Expert Comment

by:trkcorp
ID: 6865140
How are you connecting (DAO,ADO,RDO...) and to what type of DB?
0
 

Author Comment

by:srobia
ID: 6865175
Fortunately -- I'm connecting with ADO.  Unfortunately, I'm connecting to MSAccess
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 6865260
Well, just interrogate the state:

Dim Cn as ADODB.Connection
Dim Rs As ADODB.Recordset
Dim Cmd As ADODB.Command
Dim sState as string

Set Cn = New ADODB.Connection
'set rs, cmd, etc...
sState = GetState(Cn.State) 'returns closed?
Cn.Open "Your parameters..."
sState = GetState(Cn.State) 'returns open?
'open rs, cmd.execute, etc...
sState = GetState(Rs.State)
sState = GetState(Cmd.State)

'Get the idea?

Public Function GetState(lState as Long) as String
' State is applicable to Command, Connecton & Recordset Objects
Select Case lState
Case adStateClosed
  GetState = "Closed"
Case adStateOpen
  GetState = "Open"
Case adStateConnecting
  GetState = "Connecting"
Case adStateExecuting
  GetState = "Executing"
Case adStateFetching
  GetState = "Fetching"
End Select

0
 
LVL 4

Expert Comment

by:trkcorp
ID: 6865319
On another note, I guess you could time things if something like performance status is what you are after.  I would use API GetTickCount to see how many milliseconds operations take.  

Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long

Dim lTick as Long

lTick = GetTickCount
'DO SOMETHING
lTick = GetTickCount - lTick
MsgBox "Something took " & cstr(lTick) & " Milliseconds."
0
 

Author Comment

by:srobia
ID: 6865326
But what about acceptable times?  I mean I could get the state but if I run it and find that it is fetching after, say 5 seconds, I want to say it is a bad connection.
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 6865403
Do you realize that unless you perform asynchronous operations on your objects you will "stick" on an operation until it is completed?  Synchronously, you will do something like a connection open and this operation must complete before the next statement is execusted.  Asynchronously, you start an operation and resume execution of the next statements immediately, not waiting for completion.  And, if you perform asynchronous operations (as opposed to synchronous) that you have to write code to determine if they are still executing and what state (state here meaning is my connection open yet, do I have data in my input buffer to use although I am not through fetching all, etc...?) they are in?
These kinds of particulars will help define the direction you go in to solve your problem...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:trkcorp
ID: 6865434
On another note, do you realize there are connection and command timeout properties that you can set? For Ex setting:
Cn.ConnectionTimeOut = 5
will generate an error after 5 seconds of trying to connect?
Cmd.CommandTimeOut = 5
would generate a time out error if a query took longer than 5 seconds to execute?
0
 

Author Comment

by:srobia
ID: 6865467
I'm unsure whether or not I want to make this synchronous or asynchronous.  I was originally thinking that when the load the program that it will perform this check only once (which I know may not be the best-representation of performance).  So I could get away with synchronous.  But I was just kind of wondering what other people have done.  I want to display this to the user -- so, although the timeout property is a great idea -- it doesn't necessarily display performance back to the user.
0
 
LVL 18

Expert Comment

by:mdougan
ID: 6865624
Well, if the idea is to let the users know when the database is running slow, here are a couple of things to think of.

You could have a timer that goes off every few seconds and runs some standard query which you've timed before.  If the elapsed time (derived through using gettickcount) is in various ranges, you'll assign the proper color to your stop light.....

But, for this to be useful at all, it's going to have to run every few seconds to show the current state of the database.  If you have hundreds of clients issuing this query every few seconds, that alone is going to cause the database to run slow, even if no one is doing any actual work related queries.  

Let's say that you do have up-to-the-minute traffic lights showing the database activity level, do you think that the user will care?  If they need to see a list of clients, they will click the search button no matter what the light says.  The light will only help them to understand that the database is running slow right now.... but, in my opinion, if I run a query, and it doesn't come back right away, I KNOW that the database is not running quickly even without the little traffic lights.

So, the question I'd have is, is it worth all of the database traffic that you are going to be generating, to provide a kind of feedback to the user, that may or may not be that useful to them....
0
 

Author Comment

by:srobia
ID: 6865739
Yeah up to the minute may not be the best way to do this - -but I was also thinking to do this once (when they launch the application).  But I know that doesn't make the best sense either.  I just think it would be handy to have a nice quick visual for them to see performance -- kind of like BearShare.  I'm trying to compare the pros-cons of doing this.
0
 
LVL 4

Accepted Solution

by:
trkcorp earned 100 total points
ID: 6866006
Based on the discussion thus far, I think about all you could really do is:
1.Set the stoplight to red at start
2.Set it to yellow and begin to open your connection,query, etc.
3.Set it to green when the connection,query,etc. is established/complete and perhaps report how long that took or back to red if it fails or times out at which time you could report failure or timeout based on the error generated.
0
 
LVL 18

Expert Comment

by:mdougan
ID: 6866473
I think it's a nice idea, and if there was no overhead involved, then I think it would be a nice touch.  But, given the negative aspects, and the limited usefullness, I'd probably table the idea.
0
 

Author Comment

by:srobia
ID: 6877821
they are all good comments/suggestions.  I would table the idea but it is a nice touch (completely unnecessary though) and it I would gain favor with the users by providing 'pretty' things.  thanks for the discussion
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Opening Remote & Local Data Connection 2 51
MS Access Search and Replace Using VBA 6 58
to transfer string from C lanaguage to VBA 4 58
VB6 - Convert HH:MM into Decimal 8 53
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now