Search code examples
vb.netauthenticationdetectapplication-server

Vb.Net Detect if application server is down


I have developed a .Net application that I want to share to users through shared file in the LAN that is managed through a Domain server. When the server is up and running its fine but when the server is shut down an error comes. I have access to sql server database in that server. When server is shut down it gives a fatal error and application stops. How to detect the error of server being down? I am connecting to the server through the following code:

Dim sql As String
Dim daCourseMaster As SqlDataAdapter

        Try
            sqlConn = New SqlConnection(connString)
            sqlConn.Open()

            sql = " ... "

            daCourseMaster = New SqlDataAdapter(sql, sqlConn)
            daCourseMaster.Fill(dsDataset, "table")
            dvRegister = New DataView
            dvRegister = dsDataset.Tables("courseRegisters").DefaultView
            dgvCourseRegister.DataSource = dvRegister


        Catch ex As Exception
            MsgBox(Err.Description)
        End Try

Now there might be different reasons why user can not login to the server: either the server name is wrong or user name or password is wrong or thebserver might be shut down! How to differentiate between these reasons to let the user know what might be the reason to failed login?


Solution

  • Use this code before the code that do the sharing (if the code in a Sub):

     If Not My.Computer.Network.Ping(" You Server Name or Server IP") Then Exit Sub
    

    or (if the code in a Function):

     If Not My.Computer.Network.Ping(" You Server Name or Server IP") Then Exit Function