Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Testing for DB Connectivity

Posted on 2011-09-20
5
Medium Priority
?
233 Views
Last Modified: 2012-05-12
The app I'm writing is to be put on a laptop where it may or might not have connectivity to a SQL Server database (depending on whether the user is in the field or in a motel room).

Other than attempting to open a connection and waiting to see if it will time out, is there any other way to test to see if there is a database connection available?

TIA
0
Comment
Question by:Clif
  • 3
  • 2
5 Comments
 
LVL 10

Author Comment

by:Clif
ID: 36567865
Currently I have a function like this:
Public Function validConnection() As Boolean
    Dim bRetVal As Boolean = True
    Dim sqlConn As New SqlConnection() 'The SQL Connection

    sqlConn.ConnectionString = m_sConnectString 'Set the Connection String
    Try
        sqlConn.Open() 'Open the connection
    Catch
        bRetVal = False
    End Try
    sqlConn.Close()
    Return bRetVal
End Function

Open in new window

0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 36570284
First step is to see if the network is connected

Use My.Computer.Network.IsAvailable

http://msdn.microsoft.com/en-us/library/d1e9b5cx(v=vs.80).aspx

Then you can ping the server
http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping.aspx

Or you can just reduce the SQLConnection.ConnectionTimeOut and try to connect to the server. The default timeout is 15 seconds.
0
 
LVL 10

Author Closing Comment

by:Clif
ID: 36573517
SQLConnection.ConnectionTimeOut is readonly

However testing for the network and pinging the server is enough.

Thanks.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36576013
The connection timeout can be set using the connection string.
0
 
LVL 10

Author Comment

by:Clif
ID: 36576239
Oh, right.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

916 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