Page 1 of 1

how do I use sshOptions?

Posted: Thu 26 Jan 2006 17:15
by jbrahy
shouldn't this work? I get a connection timed out but I know

[code]
mySqlConnection.UserId = "dbusername";
mySqlConnection.Password = "dbpassword";
mySqlConnection.Host = "hostname.com";
mySqlConnection.Database = "databasename";
mySqlConnection.Port = 3306;
mySqlConnection.SshOptions = new SshOptions("hostname.com", "sshusername", "sshpassword");
mySqlConnection.Open();
[/code]

I'm using the same hostname for both of them because the db server that I want to connect to is also the sshserver.

Posted: Fri 27 Jan 2006 15:57
by SecureGen
Before opening connection you should turn on the SSH protocol by following command:
mySqlConnection.Protocol = MySqlProtocol.SSH;

I can not see such line in your code. Do you have it?

Posted: Fri 27 Jan 2006 17:25
by jbrahy
Yes, I have tried that, this the function that I am trying to write.


protected bool OpenConnection()
{
mySqlConnection.UserId = "dbusername";
mySqlConnection.Password = "dbpassword";
mySqlConnection.Database = "dbname";
mySqlConnection.Port = 3306;
mySqlConnection.Host = "hostname.com";
mySqlConnection.Protocol = MySqlProtocol.Ssh;
mySqlConnection.SshOptions = new SshOptions("hostname.com", 22, "sshusername", "sshpassword");

bool isSuccessful = false;

try
{
mySqlConnection.Open();

if (mySqlConnection.State == ConnectionState.Open)
{
isSuccessful = true;
}
else
{
isSuccessful = false;
}
}
catch (Exception ex)
{
MessageBox.Show("MainForm: " + ex.Source + ": " + ex.Message);
}
return isSuccessful;
}



There is a firewall between me and my dbserver that will not allow traffic on port 3306, so I was expecting that the ssh options would do port forwarding for local 3306 to remote 3306 but that doesn't seem to work.

Could you explain what functionality the sshoptions gives me? Does it do port forwarding/tunneling? If so how should I set up the remote database server?

I am able to connect if I create a tunnel of local port 3306 of my local machine to the remote machine with putty.

Posted: Mon 30 Jan 2006 10:45
by SecureGen
The functionality of SSH options implements port forwarding/tunnelling. You are trying to use it in appropriate way. You do not need additional settings to the DB server since the traffic between DB server SSH server is not secure. Only SSH server MySql client traffic is encrypted.

Please let me know values of the following variables when you break in the catch block: MySqlConnection.ConnectionString, ex.Message, ex.StackTrace. It will help me to reproduce your situation.

When you try to connect using Putty do you also use UserName+Password authentication method?
Since you have SSH server and DB server on the same computer you can try to use mySqlConnection.Host = "localhost";

Posted: Mon 30 Jan 2006 22:53
by jbrahy
When I connect via putty, I do use username and password auth, I tried host=localhost and also leaving it out and also using the actual server name but none of them worked.

the connection string was set to User ID=dbusername;Password=dbuserpassword;Database=database;Protocol=Ssh

ex.Message: Can't connect to MySQL server on 'localhost' (10061)

ex.Stacktrace: at CoreLab.MySql.b.a(String A_0, String A_1, String A_2, String A_3, Int32 A_4, String A_5, Int32 A_6, SshOptions A_7, sslOptions A_8)
at CoreLab.Mysql.MysqlInternalConnection.Connect(String UserId, String password, String host, String database, Int32 port, Int32 ConnectionTimeout, MysqlProtocol protocol, Boolean compress)
at CoreLab.Mysql.MysqlInternalConnection..ctor(ab connectionOptions)
at CoreLab.Mysql.a7.a(DbConnectionOptions a_9 Object a_1, DbConnectionBase A_2
at CoreLab.Common.DbConnectionFactory.a(DbConnectionPool A_0, DBConnectionOptions a_1)
at CoreLab.Common.DBConnectionPool.a()
at CoreLab.Common.DBConnectionPool.GetObject()
at CoreLab.Common.DBConnectionFactory.a(DbConnectionBas A_0)
at CoreLab.Common.DBConnectionClosed.Open(DbConnectionBase outerConnection)
at CoreLab.MySQL.MySQLConnection.Open()
at ad2Workflow.Section.ProjectListing.OpenConnection() in c:\file.cs

Posted: Fri 10 Feb 2006 13:53
by SecureGen
The problem is that connection string does not contain necessary SSH options. It is because of problem in MySQLDirect .NET Data Provider. We have fixed this issue. Fix will be available in the next build.
Meanwhile you can use the following code as a workaround:

mySqlConnection.UserId = "dbusername";
mySqlConnection.Password = "dbpassword";
mySqlConnection.Database = "dbname";
mySqlConnection.Port = 3306;
mySqlConnection.Host = "hostname.com";
mySqlConnection.Protocol = MySqlProtocol.Ssh;
mySqlConnection.SshOptions.Host = "hostname.com";
mySqlConnection.SshOptions.Port = 22;
mySqlConnection.SshOptions.User = "sshusername";
mySqlConnection.SshOptions.Password = "sshpassword";

......

Posted: Wed 15 Nov 2006 19:10
I'm getting this error now. I've done as the previous messages suggested and added the line assignments, but no SSH connection and I get the 10061 error. Any ideas?

conn.UserId = "dbuserid";
conn.Password = "dbpasworod";
conn.Host = "local IP address for after SSH";
conn.Database = "db";
conn.Port = 3306;
conn.Protocol = MySqlProtocol.Ssh;
conn.SshOptions.Host = "external addr for SSH";
conn.SshOptions.Password = "ssh password";
conn.SshOptions.User = "sshuser";

Posted: Fri 17 Nov 2006 13:22
by Alexey
Try to set SshOptions.Port attribute.