use Try Catch Block. If connection fails use yor message box in catch block.
Dim sqlCnn As New SqlConnection
Dim connString as string = "Your Connection String"
Try
sqlCnn = New SqlConnection(connString)
sqlCnn.open()
Catch ex As SqlException
MsgBox("Login Failed")
End Try