I have a button in an app that when pressed will establish a connection with a SSH Server and portforward to a mysql server. The issue is, I can't seem to correctly establish a tunnel connection with the mysql server via SSH.net library. I can however use the mysql .net library + putty & portforward to establish a mysql connection when the button is pressed.
I believe what the issue is that my connection string for mysql states the Server as localhost, which should be needed to establish a local connection, right? However using SSH.net library PortFowardLocal I believe the boundhost is not needed (which would be localhost). Of course when I remove the bound host I get a a runtime error.
According to the mysql net documentation a Server needs to be stated in order to connect to a mysql DB.
http://dev.mysql.com/doc/refman/5.0/en/connector-net-programming-connecting-connection-string.html
Sorry code is in VB:
Dim client AsNew SshClient("IP, 22, "User", "password")Dim port1 = New ForwardedPortRemote("", 3306, "local IP", 3306)'Check for Textbox errorsIf textBoxEmail.Text.Length = 0 Then MessageBox.Show("Enter a Email Address", MessageBoxButton.OK) textBoxEmail.Focus()ElseIfNot Regex.IsMatch(textBoxEmail.Text, "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$") Then MessageBox.Show("Enter a vaild Email Address", MessageBoxButton.OK) textBoxEmail.[Select](0, textBoxEmail.Text.Length) textBoxEmail.Focus()'No Textbox errors? Carry on..Else'Connect to SSH ServerTry client.Connect()'Portforward client.AddForwardedPort(port1) port1.Start()Catch ex As Exception loginmsg.Text = "Error! Click (?) for help."EndTryDim email AsString = textBoxEmail.TextDim password AsString = passwordBox1.PasswordDim connStr AsString = "Server=localhost;"& _"Database=;"& _"User Id=;Password=;"Dim connection AsNew MySqlConnection(connStr)Try connection.Open()Catch ex As Exception loginmsg.Text = "Login Error. Click (?) for help."EndTryDim cmd AsNew MySqlCommand("Select * from reg_user where Email='"+ email + "' and password='"+ password + "'", connection) cmd.CommandType = CommandType.TextDim adapter AsNew MySqlDataAdapter() adapter.SelectCommand = cmdDim dataSet AsNew DataSet() adapter.Fill(dataSet)If dataSet.Tables(0).Rows.Count> 0 Then mainwindow.Show() Close() Else MessageBox.Show("Please enter existing username/password.", MessageBoxButton.OK)EndIf connection.Close() port1.Stop() client.Disconnect()
Thanks for any help!