代码之家  ›  专栏  ›  技术社区  ›  Arpit Gupta

随机MySQL异常-更改数据库时“读取流失败”

  •  0
  • Arpit Gupta  · 技术社区  · 7 年前

    这个问题已经在我们的生产上很久了。 有成千上万的用户的机器一直试图同时连接到MySQL,并通过不断根据需要更改数据库来对多个数据库进行查询。

    要更改数据库,这是客户机所具有的-

    private MySqlConnection Conn;
    
    public void ChangeDatabase(string DatabaseName)
    {
        if (Conn.State != ConnectionState.Open)
        {
            Conn.Open();
        }
        Conn.ChangeDatabase(DatabaseName);
    }
    

    根据我们的猜测,在某些情况下,当数据库发生更改时,我们会得到-

    [捕获到的标准异常:MySql.Data.MySqlClient.MySql Exception]对用户的主机'.'.'.'.'.'.'.'.'.'-'使用方法'MySql'.native'.password'的身份验证失败,并显示消息:读取流失败。

    这是堆栈跟踪-

        Void Trace(System.Exception) [FileName: ; Line:0].
        Void TimerProcess_Elapsed(System.Object, System.Timers.ElapsedEventArgs) [FileName: ; Line:0].
        Void MyTimerCallback(System.Object) [FileName: ; Line:0].
        Void CallCallbackInContext(System.Object) [FileName: ; Line:0].
        Void RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) [FileName: ; Line:0].
        Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) [FileName: ; Line:0].
        Void CallCallback() [FileName: ; Line:0].
        Void Fire() [FileName: ; Line:0].
        Void FireNextTimers() [FileName: ; Line:0].
        Void AppDomainTimerCallback() [FileName: ; Line:0]. at
        MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.AuthenticationFailed(Exception ex) at
        MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket() 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.MySqlConnection.Open() at
        FSCCClientUploadServiceLive.ProcessClientUpload.TimerProcess_Elapsed(Object sender, ElapsedEventArgs e)
    ----------------------------------------------------------
    Time stamp 18/09/2018 12:25:48.325
    Thread details 27
    Message:    [InnerException] Reading from the stream has failed.
    Detail: [Source] MySql.Data
    Stack Trace:
        Void Trace(System.Exception) [FileName: ; Line:0].
        Void TimerFinish_Elapsed(System.Object, System.Timers.ElapsedEventArgs) [FileName: ; Line:0].
        Void MyTimerCallback(System.Object) [FileName: ; Line:0].
        Void CallCallbackInContext(System.Object) [FileName: ; Line:0].
        Void RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) [FileName: ; Line:0].
        Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) [FileName: ; Line:0].
        Void CallCallback() [FileName: ; Line:0].
        Void Fire() [FileName: ; Line:0].
        Void FireNextTimers() [FileName: ; Line:0].
        Void AppDomainTimerCallback() [FileName: ; Line:0].
           at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
       at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
       at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
    ----------------------------------------------------------
    Time stamp 18/09/2018 12:25:49.093
    Thread details 27
    Message:    [InnerException] Attempted to read past the end of the stream.
    Detail: [Source] MySql.Data
    Stack Trace:
        Void Trace(System.Exception) [FileName: ; Line:0].
        Void TimerFinish_Elapsed(System.Object, System.Timers.ElapsedEventArgs) [FileName: ; Line:0].
        Void MyTimerCallback(System.Object) [FileName: ; Line:0].
        Void CallCallbackInContext(System.Object) [FileName: ; Line:0].
        Void RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) [FileName: ; Line:0].
        Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) [FileName: ; Line:0].
        Void CallCallback() [FileName: ; Line:0].
        Void Fire() [FileName: ; Line:0].
        Void FireNextTimers() [FileName: ; Line:0].
        Void AppDomainTimerCallback() [FileName: ; Line:0].
           at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)
       at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
    

    这个问题不是经常出现的。一切正常时,突然不知从哪里冒出来。

    0 回复  |  直到 7 年前
        1
  •  1
  •   user10792816    7 年前

    解决方案1:

    解决方案2: 如果需要SSL,服务器标识很重要,需要验证。服务器需要internet连接才能进行证书验证。请注意,加密API不会为每个进程更新CTL。CTL保持在操作系统级别。一旦将服务器连接到internet并与服务器建立SSL数据库连接,CTL将自动更新。然后您可以断开internet连接。请再次注意,CTL有其到期日期,在此之后,Windows需要再次更新它。这可能在几个月后发生。

    解决方案3: 如果需要SSL,但服务器标识不重要。通常,在这种情况下,SSL仅用于加密网络传输。我们可以关闭CTL更新:

    1. 按Win+R打开“Run”对话框,键入“gpedit.msc”(不带引号),然后按Enter键
    2. 在“详细信息”面板中,双击“关闭自动根证书更新”,单击“启用”,然后单击“确定”。这一改变将立即生效 没有 重新启动。

    https://blog.csdn.net/fancyf/article/details/78295964

        2
  •  0
  •   Poppy    6 年前

    我读了很多解决方案,最困惑和出现的地方是这个链接,因为它被提及了很多。 https://blog.csdn.net/fancyf/article/details/78295964

    在我的例子中,当连接到mySQL服务器时,本地运行良好。 但是当部署到WindowsServer2012 R2时,我得到了错误。

    谷歌搜索一段时间后的解决方案是:

    通过将此添加到连接字符串来增加连接超时: 连接超时=30 https://www.connectionstrings.com/mysql-connector-net-mysqlconnection/specifying-connection-attempt-timeout/

    所以我认为2台服务器需要时间协商和握手,所以默认的时间框架是不够的。