Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Testing for DB Connectivity

Posted on 2011-09-20
5
Medium Priority
?
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

721 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