社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  DATABASE

MySqlClient在其中。net MVC web应用程序正在尝试作为请求主机连接

user16027534 • 3 年前 • 1264 次点击  

我对网络应用非常陌生,所以如果问题是由天真造成的,我深表歉意,然而,我完全不知所措。

我有一个基本的ASP。net core MVC应用程序运行在Apache2后面的Ubuntu20.4服务器上,每当该应用程序收到请求时,Mysqlclient返回一个异常:

MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to host '' for user '' using method 'sha256_password' failed with message: Access denied for user ''@'{the requesting IP}' (using password: NO)

我希望传递给客户机的连接字符串实际上是与所有正确参数一起传递的,这些参数已在我的本地计算机(Win10)上测试过。这两种方法都是通过运行MySQL的本地实例和远程连接到ubuntu服务器上的MySQL服务器,两种实例都能正常运行。

我唯一的假设是,MysqlClient试图以某种方式使用“@”{My IP}的网页请求者凭据,这显然会导致访问被拒绝,但我不确定这是如何发生的或为什么发生的。

我的连接字符串是:

"SERVER=127.0.0.1; DATABASE=somedb; UID=someuser; PASSWORD=SomePassword;"

然后,我的连接请求是通过以下内容发出的,而不需要对默认的MySqlConnection对象进行任何修改:

private static MySqlConnection dbConnection;
dbConnection = new MySqlConnection(connectionString);

我从应用程序中得到的错误有:

fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
      An unhandled exception has occurred while executing the request.
MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to host '' for user '' using method 'sha256_password' failed with message: Access denied for user ''@'{my IP}' (using password: NO)
 ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Access denied for user ''@'{my IP}' (using password: NO)
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.AuthenticationFailed(Exception ex)
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ContinueAuthentication(Byte[] data)
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.HandleAuthChange(MySqlPacket packet)
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(Boolean reset)
   at MySql.Data.MySqlClient.NativeDriver.Authenticate(String authMethod, Boolean reset)
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/133728
 
1264 次点击  
文章 [ 1 ]  |  最新文章 3 年前
Laurent
Reply   •   1 楼
Laurent    4 年前

我认为你的连接字符串可能不正确,我不是MySql专家,但根据一些谷歌结果,“密码”应该是“Pwd”,字段是PascalCase。 此外,您可能需要指定一个TCP端口。

连接字符串示例:

Server=127.0.0.1;Port=1234;Database=somedb;Uid=someuser;Pwd=somePassword;