最近搞 .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. Linux中的RCU的那点事

      原文:https://zhuanlan.zhihu.com/p/67520807     今天来讲一下这Linux内核中的RCU(Read Copy Update,读复制更新)机制. 我主要参考的 ...

  2. CentOS7下载配置PostgreSQL的pgAgent运行代理作业

    1.安装PostgreSQL 参考官方文档https://www.postgresql.org/download/linux/redhat/,运行如下命令 yum install https://do ...

  3. centos7 下gcc离线安装

    1.在centos安装镜像文件ios中的Packages文件夹中需找安装文件: 把需要的文件直接复制出来就行. 这里提醒的一点是,如果用命令行进入该文件夹,因为文件路径带空格,所以需要加上双引号: [ ...

  4. Map List Set的区别

    Map List Map的主要区别如下: set List 是实现了Collection接口的子接口:Map本身就是一个接口: list数据存放时有序的,允许有重复元素:set数据存放时无序的,不允许 ...

  5. 17、在vue中引用移动端框架Vux:

    1:使用vue-cli创建好项目(此处省略步骤)2:在项目中安装vux:npm install vux --save3:​安装vux-loader:npm install vux-loader --s ...

  6. Java 之 可变字符序列:字符串缓冲区(StringBuilder 与 StringBuffer)

    一.字符串拼接问题 由于 String 类的对象内容不可改变,所以每当进行字符串拼接时,总是会在内存中创建一个新的对象. Demo: public class StringDemo { public ...

  7. Python列表,元组,字典,集合

    列表 Python中列表是可变的,这是它区别于字符串和元组的最重要的特点,一句话概括即:列表可以修改,而字符串和元组不能. 列表追加数据的方法:append(),extend(数组),insert(位 ...

  8. Linux CentOS7 安装FTP服务器

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/qq_39680564/article/de ...

  9. 无法读取例程 &ROUTINE 中配置文件选项 FND_DEVELOPER_MODE

    问题描述:OM>发运>事务处理,进入此界面,FORM出现报错信息:无法读取例程 &ROUTINE 中配置文件选项 FND_DEVELOPER_MODE 解决办法:在系统管理员下,设 ...

  10. Oracle数据库备份还原笔记

    Oracle数据库备份还原笔记 通过查阅资料知道Oracle备份还原的方式有三种.分别的是导出/导入.热备份和冷备份.导出/导入是一种逻辑备份.而热备份和冷备份是物理备份.[参考资料(https:// ...