Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: PortForwading Bug

$
0
0
I read last comments, but I'm not able to solve.

I do this next test.
I made a TEMP database on two sql servers availables with 2 freeSSH servers for each network.
I create a temp users for SSH server
With a blank Windows form project I draw 2 buttons and 2 richtectbox. I used VB.

From Click event on button 1 I write to conenct to server 1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        RichTextBox1.AppendText("Connecting...." & vbNewLine)

      

        Dim client As SshClient = New SshClient("77.73.166.66", 1443, "tempuser", "tempuser")
        Try
            client.Connect()
            RichTextBox1.AppendText("Connected to 77.73.166.66:1443" & vbNewLine)
            Dim fw As ForwardedPortLocal = New ForwardedPortLocal("127.0.0.1", 14444, "192.168.1.3", 1433)
            client.AddForwardedPort(fw)
            fw.Start()

            Dim query As String = "select * from temp"
            Dim CadenaDEconexion As String = "data source =127.0.0.1,14444; initial catalog = TEMP; user id = tempuser; password = tempuser; MultipleActiveResultSets=True"

            Dim cnn As New SqlConnection(CadenaDEconexion)
            Dim cmd As New SqlCommand
            Dim rdr As SqlDataReader
            cnn.Open()
            cmd.Connection = cnn
            cmd.CommandText = query
            rdr = cmd.ExecuteReader

            While rdr.Read
                RichTextBox1.AppendText(rdr(0) & " " & rdr(1) & vbNewLine)
            End While

            rdr.Close()
            cnn.Close()

            fw.Stop()
            client.RemoveForwardedPort(fw)
            client.Disconnect()
        Catch ex As Exception

        End Try
    End Sub
On the Click from button2 to connect to server 2


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        RichTextBox2.AppendText("Connecting...." & vbNewLine)
        Dim client As SshClient = New SshClient("77.73.161.57", 1443, "tempuser", "tempuser")
        Try
            client.Connect()
            RichTextBox2.AppendText("Connected to 77.73.161.57:1443" & vbNewLine)
            Dim fw As ForwardedPortLocal = New ForwardedPortLocal("127.0.0.1", 14444, "192.168.1.3", 1433)
            client.AddForwardedPort(fw)
            fw.Start()

            Dim query As String = "select * from temp"
            Dim CadenaDEconexion As String = "data source =127.0.0.1,14444; initial catalog = TEMP; user id = tempuser; password = tempuser; MultipleActiveResultSets=True"

            Dim cnn As New SqlConnection(CadenaDEconexion)
            Dim cmd As New SqlCommand
            Dim rdr As SqlDataReader
            cnn.Open()
            cmd.Connection = cnn
            cmd.CommandText = query
            rdr = cmd.ExecuteReader

            While rdr.Read
                RichTextBox2.AppendText(rdr(0) & " " & rdr(1) & vbNewLine)
            End While

            rdr.Close()
            cnn.Close()

            fw.Stop()
            client.RemoveForwardedPort(fw)
            client.Disconnect()


        Catch ex As Exception

        End Try
    End Sub
TEST steps:

I Start application:
Button1 Connect to Server1----- OK
Query restult------>
Connected to 77.73.166.66:1443
Full 1
My name
Close application

Start application
Button2 Connect to server2 ----- OK
Query result ----->
Full 2
My name 2
Close application


Start application
Button1 Connect to server 1 ---> ok
Query Result --->
Full 1
My name
WITHOUT close application
Button2 Connecto to server 2 ---> Client.IsConnected shows True
but...Query result--->
Full 1
My name


Returns the results from Client1.

You can use my servers data to try if you need.

What I'm doing wrong??

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>