0

I'm using VB.NET to create a simple application which will test if a variety of SQL Server are available online.

I have the code below, but the timeout is not working and it simply waits forever rather than throwing a timeout error. I have put breakpoints in and, as this is in an loop of IP's, it never progresses if the IP being checked is unavailable.

 Dim data As New SqlClient.SqlConnection("Data Source=DatabaseIP;Initial Catalog=POS;Integrated Security=False;User ID=sa;Password=;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False".Replace("DatabaseIP", IP))

Try
    data.Open()
Catch ex As Exception
    Dim stophere As String = ""
    TextBox1.Text += IP + vbNewLine
End Try
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

0

Connect Timeout=15 is not correct, try it with Connection Timeout=15

David Sdot
  • 2,343
  • 1
  • 20
  • 26
0

To connect with Database, following code is enough,

Dim data As New SqlClient.SqlConnection("Data Source=DatabaseIP;Initial Catalog=POS;Integrated Security=False;User ID=sa;Password=;")
K.Suthagar
  • 2,226
  • 1
  • 16
  • 28
  • And this will use the default timeout settings, which is NOT actually happening. My question is as to WHY the timeout is not working, and how to get the connection request to timeout and indicate that the DB is not accessible. – Lord Nodral III Dec 08 '16 at 14:50