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
        Try
            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 & "';"
            connection.Open()
            command.Connection = connection
        adaptor.SelectCommand = command
        adaptor.Fill(dataset1, "0")
        Dim count = dataset1.Tables(0).Rows.Count
        If count > 0 Then
                MsgBox("ok")
                End
        Else
            MsgBox("Command Code Invalid")
            TextBox1.Clear()
            Failure_Splash.Show()
            Me.Close()
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
            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.

had not thought of that. Thanks....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.