I have a app, that requires login with SQL server as backend.
I have users who are on laptops and not always connected to the network.

I want a way to check for the SQL server, and if it does not exist then roll over to local auth
for local info.

My app works fine if connected to SQL, if SQL is not there the app locks up and takes a long time to popup saying
could not connect to sql and does not show local access options.

Here is code:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim command As New SqlClient.SqlCommand
        Dim adaptor As New SqlClient.SqlDataAdapter
        Dim dataset1 As New DataSet
            connection.ConnectionString = ("Data Source=OPS\DRAGONNET;Initial Catalog=LCARS;Persist Security Info=True" & _
              ";User ID=***;Password=*************")
            command.CommandText = "SELECT * FROM Code WHERE cmdlvl='" & TextBox2.Text & "' AND cmdcode='" & TextBox1.Text & "';"
            command.Connection = connection
        adaptor.SelectCommand = command
        adaptor.Fill(dataset1, "0")
        Dim count = dataset1.Tables(0).Rows.Count
        If count > 0 Then
            MsgBox("Command Code Invalid")
            End If
        Catch ex As Exception
            MsgBox("No SQL")
            Exit Sub
        End Try
    End Sub`

You could try pinging the server at startup to see if the machine is accessible. That would get a much faster response than trying to connect and waiting for the timeout.

This article has been dead for over six months. Start a new discussion instead.