探索MySql.Data.dll

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:
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
本文转自chy710博客园博客,原文链接:http://www.cnblogs.com/chy710/archive/2007/12/30/1020801.html ,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
7月前
|
SQL 关系型数据库 MySQL
Mysql source 导入
Mysql source 导入
51 0
Mysql source 导入
|
4月前
|
关系型数据库 MySQL
【XAMPP启动mysql报错】Port 3306 in use by ““C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld“……
【XAMPP启动mysql报错】Port 3306 in use by ““C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld“……
|
关系型数据库 MySQL
Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
820 2
Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
|
关系型数据库 MySQL 数据库
mysql无法重启,Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
mysql数据库经常会遇到各种问题,这里是无法重启的一种情况,总结一遍以后再遇到相同问题及时解决,也希望能帮到像我一样的小白!
mysql无法重启,Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
|
关系型数据库 MySQL 数据库