-1

I would like to connect my VB.net application remotely with SQL database server which is placed on different location.

I installed LogMeIn Hamachi on both the server and client machine and joined existing network on the client machine.

I followed the steps provided in this tutorial to enable TCP connection for SQL Server installed on server machine.

I used the following connection string and called Hascon() on windows form load event to test the connection. Either I am not getting any error also the application is not responding when I build the VB.net application.

Private conn As New SqlConnection With {.ConnectionString = "Data Source=IP address provided by Hamachi,1433;Network Library=DBMSSOCN;Initial Catalog=SIIU;User ID=sa;Password=12345;"}
Public Function Hascon() As Boolean
        Try
            Sconn.Open()
            Return True
            Sconn.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        End Try
End Function

I have searched in the Internet and tried all the possible solutions but non of solved the problem.

What could be the problem? Any ideas?

Thanks,

Mederic
  • 1,949
  • 4
  • 19
  • 36
user8328
  • 31
  • 5

1 Answers1

0

You can use simple function like this to test your connection:

Note about Hamachi:

Remember if you use Hamachi you might need to authorize the port in the firewall and anti-virus as well as on your box.

Here there is no need for the con.Close() since I implemented Using which is what you should always do for IDisposable.

Public Function IsConnectionPossible(ByVal ConnectionString As String) As Boolean
    Dim Result As Boolean = False
    Try
        Using con As New SqlClient.SqlConnection(ConnectionString)
            'Open the connection
            Try
                con.Open()
            Catch ex As Exception
                Debug.WriteLine(ex.Message)
            End Try
            'Get the state
            If con.State = ConnectionState.Open Then
                Result = True
            End If
        End Using
    Catch ex As Exception
        Debug.WriteLine(ex.Message)
    End Try
    Return Result
End Function

And you can simply call like this:

IsConnectionPossible("Data Source=IP address provided by Hamachi,1433;Network Library=DBMSSOCN;Initial Catalog=SIIU;User ID=sa;Password=12345;")

Note this function will purely test the connection it won't be practical to implement this function to open connections for future uses. For that I would recommend using a class.

Mederic
  • 1,949
  • 4
  • 19
  • 36
  • I configured the firewall to allow the sql server and the Port number 1433, TCP and 1434, UDP before. I wrote the above sample code and called IsConnectionPossible() on button click event , its not responding. – user8328 May 30 '17 at 12:35
  • @user8328 if you need help wee need information is not responding wont help much. do a debug step by step using a breakpoint and see which line makes it stuck – Mederic May 30 '17 at 12:36
  • I used Try ...Catch ...but it's not throwing error. How could I do that will you help me...Thanks – user8328 May 30 '17 at 12:39
  • @user8328 Read what i said: **QUOTE:** `if you need help wee need information is not responding wont help much. do a debug step by step using a breakpoint and see which line makes it stuck` – Mederic May 30 '17 at 12:40
  • Please help me how can I do step by step debug using break point. I'm new to vb.net. – user8328 May 30 '17 at 12:44
  • did you try google?: https://www.google.fr/search?q=vb.net+using+breakpoint also https://www.google.fr/search?q=vb.net+step+through+code – Mederic May 30 '17 at 12:47