使用ssh.net C#连接到远程mySQL服务器,为什么使用密码:NO?

时间:2015-06-02 12:51:47

标签: c# mysql ssh

    public void getConnection()
            {

                PasswordConnectionInfo connectionInfo = new PasswordConnectionInfo(AccessDBModel.Host,AccessDBModel.User,AccessDBModel.Pwd); 
                connectionInfo.Timeout = TimeSpan.FromSeconds(30);
                using (var client = new SshClient (connectionInfo)) 
                {
                    try
                    {
                        client.Connect();
                        if(client.IsConnected)
                        {
                            Console.WriteLine("SSH connection is started!");
                        }else
                        {
                            Console.WriteLine("SSH connection failed!");

                        }
                        var portFwdL = new ForwardedPortLocal(AccessDBModel.SqlIPA,AccessDBModel.SqlPort,AccessDBModel.SqlHost,AccessDBModel.SshPort);
                        client.AddForwardedPort(portFwdL);
                        portFwdL.Start();
                        if(portFwdL.IsStarted){
                            Console.WriteLine("Port forwarding is started!");
                        }else{
                            Console.WriteLine("Port forwarding failed!");
                        }

                        string strConnection = AccessDBModel.SqlConn;
                        MySqlConnection conn = new MySqlConnection(strConnection); 
                        MySqlDataAdapter dataAdapter = new MySqlDataAdapter();
                        conn.Open();



                    }catch(Exception e)
                    {
                        Console.WriteLine(e.ToString());
                    }
                }
       }

我正在尝试使用

using MySql.Data.MySqlClient;
using Renci.SshNet;
using Renci.SshNet.Common;

连接到远程mysql服务器,我参考 https://www.youtube.com/watch?v=YUhlS47SccU&spfreload=10

但是第一个2连接已经启动,但是当我执行conn.open()时,它显示:

  

MySql.Data.MySqlClient.MySqlException:对主机的身份验证   ' 127.0.0.1'对于用户'用户名'使用方法' mysql_native_password'   消息失败:用户拒绝访问   '用户名' @'的remotehostname' (使用密码:否)--->   MySql.Data.MySqlClient.MySqlException:拒绝用户访问   ' dataviz15' @' bastet.labs.esilv.fr' (使用密码:否)at   MySql.Data.MySqlClient.MySqlStream.ReadPacket()[0x00000] in   :0点   MySql.Data.MySqlClient.NativeDriver.ReadPacket()[0x00000] in   :0点   MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket   ()[0x00000] in:0 ---内部异常结束   堆栈跟踪---

0 个答案:

没有答案