zoukankan      html  css  js  c++  java
  • 探索MySql.Data.dll

    ADO.NET Driver for MySQL
    MySql.Data.dll
    是.Net访问MySQL数据库的一个驱动,完全ADO.NET数据访问模式,由MySQL官方提供,有多个版本可选择。

    最早使用的环境:.Net2.0+MySQL5.x+MySQL.data.dll 1.0.7,感觉似乎很稳定,一直没什么大问题。随着系统升级,尝试更新MySql.Data.dll版本(1.07版本官方早不提供下载了,现在最新版本分别是:1.0.10,5.0.8,5.1.4),问题出现了,经常会出现异常
    The timeout period elapsed prior to completion of the operation or the server is not responding
    在业务逻辑及数据不变的情况下,仅更换MySql.Data.dll就出现异常让我费尽了心思。

    其实在SQLServer中有时也出现此问题,有人建议设置ConnectionTimeoutCommandTimeout时长来解决,MySql.Data.dll中也有这些属性,下载了MySql.Data.dll的源码,看了下,似乎发现了一线希望,在1.07版本的源码中ConnectionString.cs类中有
    [Category("Connection")]
            [Description(
    "Number of seconds to wait for the connection to succeed")]
            [DefaultValue(
    15)]
            
    public int ConnectionTimeout
            
    {
                
    get return GetInt("connect timeout"); }
            }
    只读属性,默认值为15秒,可以在连接字符串设置。
    command.cs类中有
    [Category("Misc")]
            [Description(
    "Time to wait for command to execute")]
            
    public int CommandTimeout
            
    {
                
    // TODO: support this
                get  return 0; }
                
    set  if (value != 0throw new NotSupportedException(); }
            }
    默认值是0,表示没时长限制?猜的。对其赋值如不为0,则抛出异常,也就是说赋值只能为0,那也就是该属性只读了?其值不可改变。

    再来看新版本的,在5.0.8的源码中MySqlConnectionStringBuilder.cs类中有
    [Category("Connection")]
            [DisplayName(
    "Connect Timeout")]
            [Description(
    "The length of time (in seconds) to wait for a connection " +
                 
    "to the server before terminating the attempt and generating an error.")]
            [DefaultValue(
    15)]
            [RefreshProperties(RefreshProperties.All)]
            
    public uint ConnectionTimeout
            
    {
                
    get return connectionTimeout; }
                
    set 
                
    {
                    SetValue(
    "Connect Timeout", value); 
                    connectionTimeout 
    = value; 
                }

            }
    属性可读写,默认值为15秒。
    command.cs类中有
    [Category("Misc")]
            [Description(
    "Time to wait for command to execute")]
            [DefaultValue(
    30)]
            
    public override int CommandTimeout
            
    {
                
    get return commandTimeout; }
                
    set { commandTimeout = value; }
            }
    属性可读写,默认值为30秒(这些默认值感觉跟SQLServer一样的),这一点跟1.0.7就不同了。1.0.7为只读且值为0。
    我感觉前面提到的Timeout异常跟这里有很大关系,准备测试下.......
     
    PS:希望能在园子里找些用MySQL的朋友,有问题可以一起探讨,在社区建了个小组: .Net+MySQL
  • 相关阅读:
    C#/JAVA 程序员转GO/GOLANG程序员笔记大全(DAY 04)
    C#/JAVA 程序员转GO/GOLANG程序员笔记大全(DAY 03)
    C#/JAVA 程序员转GO/GOLANG程序员笔记大全(DAY 02)
    C#/Java 程序员转GO/golang程序员笔记大全(day 01)
    selenium grid配置
    JUnit和TestNG的区别
    【转载】 HttpClient、HttpURLConnection、OKHttp和Volley优缺点和性能对比
    selenide总结
    docker操作
    python连接oracle数据库
  • 原文地址:https://www.cnblogs.com/chy710/p/1020801.html
Copyright © 2011-2022 走看看