最近搞 .net项目,Dapper连接Mysql时,运行报错:

System.NotSupportedException:“No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.”

解决办法:

新建项目,选择Visual C#   ->    .Net Core    ->    控制台应用(.Net Core)

数据库语句:

CREATE TABLE `city` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Name` char(35) NOT NULL DEFAULT '',
`CountryCode` char(3) NOT NULL DEFAULT '',
`District` char(20) NOT NULL DEFAULT '',
`Population` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`),
KEY `CountryCode` (`CountryCode`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

测试代码:

 using System;
using MySql.Data.MySqlClient;
using Dapper;
using System.Collections.Generic;
using System.Linq; namespace ConsoleApp1
{ public class CityEntity
{
public int ID { get; set; }
public string Name { get; set; }
public string CountryCode { get; set; }
public string District { get; set; }
public int Population { get; set; } public override string ToString()
{
return $"ID: {ID}, Name: {Name}, CountryCode: {CountryCode}, District: {District}, Population: {Population}";
}
}
public class CityRepository
{
public List<CityEntity> Get10Cities()
{
List<CityEntity> result;
using (var conn = new MySqlConnection("Host=172.16.1.197;Port=3306;Database=mars_xusinan;Uid=root;pwd=123456"))
{
var sql = "SELECT * FROM city";
result = conn.Query<CityEntity>(sql).ToList();
} return result;
}
}
class Program
{
static void Main(string[] args)
{
var repository = new CityRepository();
var cities = repository.Get10Cities();
cities.ForEach(e =>
{
System.Console.WriteLine(e);
});
}
}
}

添加引用:用NuGet得到包

Dapper

MySql.Data

安装完后,报错自然消失,大功告成,搞了2天,坚持不放弃。

System.NotSupportedException:“No data is available for encoding 1252. For information on defining a custom encoding的更多相关文章

  1. “entities.LastOrDefault()”引发了类型“System.NotSupportedException”的异常

    问题: var entities = new ShipuPlanBLO().UserList(userId, beginDate, endDate); DateTime maxDate = entit ...

  2. Asp.Net Core 3.1 获取不到Post、Put请求的内容 System.NotSupportedException Specified method is not supported

    # 问题 是这样的,我.net core 2.1的项目,读取.获取Post请求内容的一段代码,大概这样: [HttpPost] public async Task<IActionResult& ...

  3. Bigtable:A Distributed Storage System for Strctured Data

    2006 年10 月Google 发布三架马车之一的<Bigtable:A Distributed Storage System for Strctured Data>论文之后,Power ...

  4. c#重命名文件,报错“System.NotSupportedException”类型的未经处理的异常在 mscorlib.dll 中发生”

    修改远程服务器的文件名,报错“System.NotSupportedException”类型的未经处理的异常在 mscorlib.dll 中发生”,“System.NotSupportedExcept ...

  5. 报错:System.NotSupportedException: LINQ to Entities does not recognize the method

    报错:System.NotSupportedException: LINQ to Entities does not recognize the method ...... get_Item(Int3 ...

  6. Bigtable: A Distributed Storage System for Structured Data

    https://static.googleusercontent.com/media/research.google.com/en//archive/bigtable-osdi06.pdf Abstr ...

  7. [IR] Bigtable: A Distributed Storage System for Semi-Structured Data

    良心博文: http://blog.csdn.net/opennaive/article/details/7532589 这里只是基础简述 众人说: 链接:http://blog.csdn.net/o ...

  8. 如何完全备份android在系统system分区和data分

    安德鲁斯系统备份是非常的情况下,可以使用.下面的这个python脚本.它可以用来备份整个data分:所有data分区的文件和文件夹打包data.zip.并产生recovery专用edify脚本upda ...

  9. Note: Bigtable, A Distributed Storage System for Structured Data

    Abstract Introduction::  Bigtable设计主旨:可扩地扩展到pByte级别和数千台机器的系统, 通用.可伸缩.高性能.高可用性.  不实现完整的关系数据模型,而是支持一个可 ...

随机推荐

  1. StarGAN学习笔记

    11 December 2019 20:32 来自 <https://zhuanlan.zhihu.com/p/44563641>     StarGAN StarGAN是CVPR2018 ...

  2. easydict的使用方法

    easydict的作用:可以使得以属性的方式去访问字典的值 from easydict import EasyDict as edict a=['8',2,3]a=edict()a.f=99print ...

  3. Java自学-数字与字符串 比较字符串

    Java 比较字符串 示例 1 : 是否是同一个对象 str1和str2的内容一定是一样的! 但是,并不是同一个字符串对象 package character; public class TestSt ...

  4. 计算n阶乘中尾部零的个数

    大佬答案 大佬的思路看了好久,每次看都会明白一丢丢,现在还有不明白的地方,但是要往后继续加油了,知新温故. 结论:参与阶乘的所有数的因子中只要存在一个2和一个5就会在阶乘的结果中产生一个0. 又因为因 ...

  5. 编写可维护的JavaScript-随笔(六)

    避免空比较 If(item !== null){ item.sort(); Item.forEach(function(item){ //执行代码 } } } 以上判断中item期待的是数组类型的,但 ...

  6. git的基本使用和多人协作合并管理

    1.代码版本控制工具 git 分布式 svn 集中式 2.配置git 配置用户名以及邮箱账号,用于记录用户信息 git config --global user.name 'wudaxun' git ...

  7. TensorFlow NMT的词嵌入(Word Embeddings)

    本文转载自:http://blog.stupidme.me/2018/08/05/tensorflow-nmt-word-embeddings/,本站转载出于传递更多信息之目的,版权归原作者或者来源机 ...

  8. mysql 外键的基本使用

    外键的使用条件: 两个表必须是InnoDB表,MyISAM表暂时不支持外键外键列必须建立了索引,MySQL 4.1.2以后的版本在建立外键时会自动创建索引,但如果在较早的版本则需要显式建立:外键关系的 ...

  9. 详解Linux操作系统的iptables原理及配置

    linux网络防火墙 netfilter :内核中的框架,过滤框架,网络过滤器! iptables  :实现数据过滤.net.mangle等规则生成的工具 防火墙:硬件.软件.规则(匹配规则.处理办法 ...

  10. 关于ping github.com超时的解决办法

    今天在使用git的时候执行将本地分支推送到远程分支的push操作时(同时为远程库创建和本地分支同名的分支),遇到了超时的错误,经过查询全网各位大牛的操作这里给出有效解决方式 进入C:\Windows\ ...