Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1447

Connecting with SSH (2 replies)

$
0
0
Hi,
The code below works fine and connects securely to the server and then the database but once its run a second time its hangs for about 5-6 seconds while opening the MYSQL connection and running a query. If I run this without SSH it works fine no matter how many times I run it. Any other application I have connect via SSH works fine.

Simple form with connection details in textboxs and a datagridview to display the results.

Please help going a bit mental with the coffee trying to figure it out!!!!!

Cheers,

John

private DataTable MYSQL_GET(string sQuery)
{
DataTable dt = new DataTable();

using (var client = new SshClient(txtSSH_Address.Text, txtSSH_Username.Text, txtSSH_Password.Text))
{
client.Connect();

var port = new ForwardedPortLocal("127.0.0.1", Convert.ToUInt32(txtSQL_Port.Text), "localhost", Convert.ToUInt32(txtSQL_Port.Text));
client.AddForwardedPort(port);

port.Start();

string connstr = "server=localhost;user=" + txtSQL_Username.Text + ";database=store;port=" + txtSQL_Port.Text + ";password=" + txtSSH_Password.Text + ";";

using (MySqlConnection conn = new MySqlConnection(connstr))
{
conn.Open();

MySqlDataAdapter da = new MySqlDataAdapter(sQuery, connstr);
da.Fill(dt);

conn.Close();
}

port.Stop();
client.Disconnect();

return dt;
}
}

Viewing all articles
Browse latest Browse all 1447

Trending Articles



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