System.NotSupportedException:“No data is available for encoding 1252. For information on defining a custom encoding
最近搞 .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的更多相关文章
- “entities.LastOrDefault()”引发了类型“System.NotSupportedException”的异常
问题: var entities = new ShipuPlanBLO().UserList(userId, beginDate, endDate); DateTime maxDate = entit ...
- Asp.Net Core 3.1 获取不到Post、Put请求的内容 System.NotSupportedException Specified method is not supported
# 问题 是这样的,我.net core 2.1的项目,读取.获取Post请求内容的一段代码,大概这样: [HttpPost] public async Task<IActionResult& ...
- Bigtable:A Distributed Storage System for Strctured Data
2006 年10 月Google 发布三架马车之一的<Bigtable:A Distributed Storage System for Strctured Data>论文之后,Power ...
- c#重命名文件,报错“System.NotSupportedException”类型的未经处理的异常在 mscorlib.dll 中发生”
修改远程服务器的文件名,报错“System.NotSupportedException”类型的未经处理的异常在 mscorlib.dll 中发生”,“System.NotSupportedExcept ...
- 报错:System.NotSupportedException: LINQ to Entities does not recognize the method
报错:System.NotSupportedException: LINQ to Entities does not recognize the method ...... get_Item(Int3 ...
- Bigtable: A Distributed Storage System for Structured Data
https://static.googleusercontent.com/media/research.google.com/en//archive/bigtable-osdi06.pdf Abstr ...
- [IR] Bigtable: A Distributed Storage System for Semi-Structured Data
良心博文: http://blog.csdn.net/opennaive/article/details/7532589 这里只是基础简述 众人说: 链接:http://blog.csdn.net/o ...
- 如何完全备份android在系统system分区和data分
安德鲁斯系统备份是非常的情况下,可以使用.下面的这个python脚本.它可以用来备份整个data分:所有data分区的文件和文件夹打包data.zip.并产生recovery专用edify脚本upda ...
- Note: Bigtable, A Distributed Storage System for Structured Data
Abstract Introduction:: Bigtable设计主旨:可扩地扩展到pByte级别和数千台机器的系统, 通用.可伸缩.高性能.高可用性. 不实现完整的关系数据模型,而是支持一个可 ...
随机推荐
- 我的第一个netcore2.2 api项目搭建(一)
早早就想入门netcore,一直没下定决心,这次正好碰上项目服务变更,便想着入坑试试,边学边用. 目标: 一.api使用core版的SqlSugar,集成orm,实现快速开发 二.api使用Swagg ...
- webpack等bundler是如何工作的-简化版本
webpack- why and how 首先不要被webpack做的复杂花哨的工作所迷惑,到底webpack是个啥?一句话,webpack是一个module bundler(模块打包器).多一句话, ...
- Grafana官方和社区提供的dashboard
详见:https://grafana.com/grafana/dashboards 可以在左侧配置筛选条件,非常强大. 当然Grafana中所有的Dashboard通过JSON进行共享,下载并且导入这 ...
- HDU2577 How to Type
题目链接 一道DP问题 定义dp[i][j]为敲完第i个字母的最小花费,j=1代表Caps Lock打开,j=0代表Caps Lock关闭,则有: 如果第i个字母为大写: dp[i][1]=min(d ...
- 【Java】调用摄像头进行拍照并保存【详细】以及处理no jniopencv_core in java.library.path的一种方法
[之前困扰笔者的问题描述] date:2019.12.18 网上教程很多,但是没有看见完整的,所以写一个出来. 调用摄像头需要javaCV的jar包和openCV的jar包,现在已经不需要安装包了 ...
- 基于OpenGL三维软件开发
实验原理: OpenGL在MFC下编程原理---- Windows操作系统对OpenGL的支持 在Windows下用GDI作图必须通过设备上下文(DeviceContext简写DC)调用相应的函数:用 ...
- swift - 开心一刻
let array = ["one", "two", "three", "four", "five" ...
- Linux添加用户并赋予root权限
新增用户 创建一个名为qiang,其家目录位于/usr/qiang的用户 adduser -d /usr/qiang -m qiang 或直接这样,则用户的家目录会默认为/home/目录 adduse ...
- DTC测试
DTC配置好后要在2台server之间测试下是否能使用. 1.在A台上建立ODBC的连接B. 控制面板→管理工具→ODBC Datat Source(32bit) 点击添加 选择SQL SERVER ...
- Prometheus学习笔记(5)Grafana可视化展示
目录 一.Grafana安装和启动 二.配置数据源 三.配置dashboard 四.配置grafana告警 一.Grafana安装和启动 Grafana支持查询Prometheus.从Grafana ...