• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

Test database connection

What are some good examples to test my database connection to a SQL database (SQL 2005 server)? I have some apps that run 24/7 on terminals and every now and then the network my come down with the apps still running. I'd like to write something in which they apps wouldn't have to restart once the network and database access comes back online.
0
thenrich
Asked:
thenrich
  • 3
  • 2
1 Solution
 
edemcsCommented:
You could catch the SQL Exception and parse the message for connectivity.  Then you could just handle it gracefully until it tries again and the database is up and running.
0
 
thenrichAuthor Commented:
Yea right now that's my current line of thinking as well. I was hoping the frame work had something a bit more elegant then that.
0
 
edemcsCommented:
Not that I know of.  I've been using .NET for a long time and haven't seen anything specific to this scenario.
0
Independent Software Vendors: 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!

 
edemcsCommented:
Just make sure you always close that connection in the Finally section of the Try/Catch
0
 
thenrichAuthor Commented:
Yup - i've been on .NET since beta. Was hoping maybe I missed something.
0
 
CodeCruiserCommented:
I use following in my project.



Private Sub MyApplication_NetworkAvailabilityChanged(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.Devices.NetworkAvailableEventArgs) Handles Me.NetworkAvailabilityChanged
            If My.Computer.Network.IsAvailable Then
                Try
                    If My.Computer.Network.Ping("dbase server") Then
                        frmMain.Enabled = True
                        MessageBox.Show("The connection to network has been restored.", "Network Reconnected", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    Else
                        frmMain.Enabled = False
                    End If
                Catch
                End Try
            Else
                frmMain.Enabled = False
                MessageBox.Show("It looks like you have lost the network connection to the network.", "Network Disconnected", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        End Sub

Open in new window

0

Featured Post

Technology Partners: 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!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now