可遇不可求的Question之MySqlClient访问字段返回System.Byte[]篇
2009-09-11 11:06
411 查看
症状:使用MySqlClient访问字段返回System.Byte[],但是使用ODBC访问时却不会有这种问题,返回正常字符。
分析:跟踪生成的内存中的值的确是 System.Byte[] 类型,然该类型数组中有字符的byte值。经过直接转化byte[]数据为string类型后,发现是正确的字符串。
解决:
1.发现数据库中数据表该字段的数据库类型为varchar(15) binary ,关键就是这个 "binary”,去掉就OK了。
2.select的时候 cast(name as varchar) name 也可以
今天补充一个方法:巨简单
3.在连接串中增加 Respect Binary Flags=false 的配置
参考资料如下:
Binary/Nonbinary Issues
There are certain situations where MySQL will return incorrect metadata about one or more columns. More specifically, the server will sometimes report that a column is binary when it is not and vice versa. In these situations, it becomes practically impossible for the connector to be able to correctly identify the correct metadat.
Some examples of situations that may return incorrect metadata are:
Execution of
When a temp table is used to process a resultset, some columns may be returned with incorrect binary flags.
Some server functions such
With the availability of
In the event that the changes required to your application would be too large, you can add 'respect binary flags=false' to your connection string. This will cause the connector to use the prior behavior. In a nutshell, that behavior was that any column that is marked as string, regardless of binary flags, will be returned as string. Only columns that are specifically marked as a
分析:跟踪生成的内存中的值的确是 System.Byte[] 类型,然该类型数组中有字符的byte值。经过直接转化byte[]数据为string类型后,发现是正确的字符串。
解决:
1.发现数据库中数据表该字段的数据库类型为varchar(15) binary ,关键就是这个 "binary”,去掉就OK了。
2.select的时候 cast(name as varchar) name 也可以
今天补充一个方法:巨简单
3.在连接串中增加 Respect Binary Flags=false 的配置
参考资料如下:
Binary/Nonbinary Issues
There are certain situations where MySQL will return incorrect metadata about one or more columns. More specifically, the server will sometimes report that a column is binary when it is not and vice versa. In these situations, it becomes practically impossible for the connector to be able to correctly identify the correct metadat.
Some examples of situations that may return incorrect metadata are:
Execution of
SHOW PROCESSLIST. Some of the columns will be returned as binary even though they only hold string data.
When a temp table is used to process a resultset, some columns may be returned with incorrect binary flags.
Some server functions such
DATE_FORMATwill incorrectly return the column as binary.
With the availability of
BINARYand
VARBINARYdata types it is important that we respect the metadata returned by the sever. However, we are aware that some existing applications may break with this change so we are creating a connection string option to enable or disable it. By default, Connector/Net 5.1 will respect the binary flags returned by the server. This will mean that you may need to make small changes to your application to accomodate this change.
In the event that the changes required to your application would be too large, you can add 'respect binary flags=false' to your connection string. This will cause the connector to use the prior behavior. In a nutshell, that behavior was that any column that is marked as string, regardless of binary flags, will be returned as string. Only columns that are specifically marked as a
BLOBwill be returned as
BLOB.
相关文章推荐
- 可遇不可求的Question之MySqlClient访问tinyint字段返回布尔值篇
- 可遇不可求的Question之MySqlClient与ODBC访问字段返回不同结果篇
- MySqlClient访问tinyint字段返回布尔值
- MySqlClient访问tinyint字段返回布尔值篇
- 可遇不可求的Question之MySqlClient的Guid 类型的映射篇
- 可遇不可求的Question之ODBC访问MySql乱码篇
- 关于C#读取MySql数据时,返回DataTable中某字段数据是System.Array[]形式
- PDO 查询mysql返回字段整型变为String型解决方法
- 非静态的字段、方法或属性“System.Web.UI.Page.ClientScript.get”要求对象引用
- MySql使用小结:允许远程访问、更改最大连接数、VARCHAR字段占用的空间、linux下安装workbench
- jdbc-mysql基础 ResultSet getGeneratedKeys 插入一条字段并返回其主键
- Rancher的管理员密码忘记怎么办?-登录RancherServer的mysql容器内,修改cattle库setting表中2个关于访问控制的字段的值
- golang mysql查询返回不定字段
- 记录:java执行mysql语句查询字段类型:timestamp返回页面显示会多出个 .0,自己如何处理的
- 简单搞一下 System.Data.OracleClient调用带blob、clob等大字段类型参数的存储过程!
- mysql的日期字段和插入日期/返回最右边5个字节right
- 可遇不可求的Question之MYSQL的10060和10061错误篇
- mysql中为用户设置数据库,数据表,字段(列)的访问权限
- 可遇不可求的Question之MYSQL获取自增ID的四种方法篇
- IIS访问WEB遇到 System.Data.OracleClient 需要 Oracle 客户端软件 8.1.7 或更高版本。问题解决方案。