Advertisement
Guest User

Untitled

a guest
May 21st, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. <appSettings>
  2. <add key="SSHHost" value="79.173.x.y"/>
  3. <add key="SSHUser" value="xyz"/>
  4. <add key="SSHPassword" value="xyz"/>
  5. <add key="SSHPort" value="22"/>
  6. <add key="SQLHost" value="79.173.x.y"/>
  7. <add key="SQLIPA" value="127.0.0.1"/>
  8. <add key="SQLPort" value="1500"/>
  9. <add key="SQLConnectionString" value="Server=127.0.0.1; Port=3306; Database=test; Uid=xyz; Pass="/>
  10. <add key="SQLSelect" value="select * from test"/>
  11. </appSettings>
  12.  
  13. PasswordConnectionInfo connectionInfo = new PasswordConnectionInfo(Const.Host, Const.Port, Const.User, Const.Password);
  14. connectionInfo.Timeout = TimeSpan.FromSeconds(30);
  15. using(var client = new SshClient(connectionInfo))
  16. {
  17. try
  18. {
  19. client.Connect();
  20. if(client.IsConnected)
  21. {
  22. Console.WriteLine("SSH connection is active");
  23.  
  24. } else
  25. {
  26. Console.WriteLine("SSH connection failed");
  27. }
  28. var portFwdl = new ForwardedPortLocal(Const.SQLIPA, Const.SQLPort, Const.SQLHost, Const.SQLPort);
  29. client.AddForwardedPort(portFwdl);
  30. portFwdl.Start();
  31. if(portFwdl.IsStarted)
  32. {
  33. Console.WriteLine("PORT forwarding is started");
  34. } else
  35. {
  36. Console.WriteLine("PORT forwarding faile");
  37. }
  38. string strConnection = Const.SQLConn;
  39. MySqlConnection conn = new MySqlConnection(strConnection);
  40. string myTablename = "test";
  41. MySqlDataAdapter myDA = new MySqlDataAdapter();
  42. myDA.SelectCommand = new MySqlCommand(Const.SQLSELECT, conn);
  43. MySqlCommandBuilder cb = new MySqlCommandBuilder(myDA);
  44. try
  45. {
  46. conn.Open();
  47. Console.WriteLine("SQL connection is active");
  48. DataSet ds = new DataSet("id");
  49. myDA.Fill(ds, myTablename);
  50. Console.WriteLine(ds.GetXml());
  51. }
  52. catch(MySqlException e)
  53. {
  54. Console.WriteLine(e.Message);
  55. }
  56. finally
  57. {
  58. conn.Close();
  59. }
  60. client.Disconnect();
  61. Console.WriteLine("SHH Disconnect");
  62.  
  63. } catch (SocketException e)
  64. {
  65. Console.WriteLine(e.Message);
  66. }
  67.  
  68. }
  69. Console.ReadKey();
  70.  
  71. $ mysql -u root -p
  72.  
  73. > use mysql;
  74. > update user set host='%' where user='plzvtl';
  75. > flush privileges;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement