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级别和数千台机器的系统, 通用.可伸缩.高性能.高可用性. 不实现完整的关系数据模型,而是支持一个可 ...
随机推荐
- DataTable求列的最大值、最小值、平均值和样本数
与sql聚合函数相似,会屏蔽null table.Compute("max(ColumnName)", "true"); table.Compute(" ...
- Kafka分布式的消息顺序
Kafka分布式的单位是partition,同一个partition用一个write ahead log组织,所以可以保证FIFO的顺序.不同partition之间不能保证顺序. 但是绝大多数用户都可 ...
- Kruskal算法&Prim算法
最小生成树是什么? Kruskal算法 图文转载自a2392008643的博客 此算法可以称为"加边法",初始最小生成树边数为0,每迭代一次就选择一条满足条件的最小代价边,加入到最 ...
- jquery实现简单定时轮播图
JS $(document).ready(function(){ var index = 0; //刚开始设置一个index,index为图片的索引值 $(".pictureDemo img ...
- MFC 解决绘图时闪烁问题的一点经验
2015-05 由于作图过于复杂和频繁,所以时常出现闪烁的情况,一些防止闪烁的方法,如下: (1)将Invalidate()替换为InvalidateRect(). Invalidate()会导致整个 ...
- 【转载】Windows系统电脑通过命令msinfo32查看系统信息
在Windows操作系统中,可以使用msinfo32的操作命令查看操作系统相关信息,通过msinfo32命令可以查看到系统摘要,包括硬件资源.组件.软件环境等系统信息.其中系统摘要包括冲突/共享.DM ...
- echarts的地图省份颜色自适应变化
在使用echarts的地图的时候省份的颜色可能随着数据的多少显示不同的颜色,但是当后台返回的数据的变化较大时可能就不好控制了,所以需要设置根据后台的数据进行自适应 将后台返回的数据中的value放入一 ...
- const关键字总结
在C语言中 const是C语言中总结 1.修饰的变量,使其具有常属性,使变量的值不能直接被改变.但是可以通过指针来间接的修改变量的值. 2.便于进行类型检查(在编译时进行类型检查),使编译对处理内容有 ...
- 大数据:Hadoop(HDFS 的设计思路、设计目标、架构、副本机制、副本存放策略)
一.HDFS 的设计思路 1)思路 切分数据,并进行多副本存储: 2)如果文件只以多副本进行存储,而不进行切分,会有什么问题 缺点 不管文件多大,都存储在一个节点上,在进行数据处理的时候很难进行并行处 ...
- linux系统IO操作
本文重点说明下面内容: 什么是标准IO,什么是文件IO? 什么是Direct IO? O_SYNC标识有什么意义? 各个层面的缓存如何同步? 还在page cache中的脏页可以读写吗? IO路径上的 ...