Skip to content

Commit 0283ad2

Browse files
committed
修复mysql使用dapper批量插入乱码的问题(由Flyash提供)
1 parent 40f5bb5 commit 0283ad2

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

Vue.Net/VOL.Core/Dapper/SqlDapper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ private int MySqlBulkInsert(DataTable table, string tableName, string fileName =
450450
FileName = path.ReplacePath(),
451451
NumberOfLinesToSkip = 0,
452452
TableName = tableName,
453+
CharacterSet = "UTF8"
453454
};
454455
bulk.Columns.AddRange(table.Columns.Cast<DataColumn>().Select(colum => colum.ColumnName).ToList());
455456
insertCount = bulk.Load();

Vue.Net/VOL.WebApi/appsettings.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
"AppUrls": {
1515
},
1616
"Connection": {
17-
"DBType": "MsSql", //MySql/MsSql/PgSql //数据库类型,如果使用的是sqlserver此处应设置为MsSql
17+
"DBType": "MySql", //MySql/MsSql/PgSql //数据库类型,如果使用的是sqlserver此处应设置为MsSql
1818
//sqlserver连接字符串
19-
"DbConnectionString": "Data Source=JSERWJRGSBCXBO7\\ADMIN;Initial Catalog=netcoredev;Persist Security Info=True;User ID=sa;Password=123456;Connect Timeout=500;",
19+
// "DbConnectionString": "Data Source=DESKTOP-G09Q22B;Initial Catalog=netcoredev;Persist Security Info=True;User ID=sa;Password=123456;Connect Timeout=500;",
2020

2121
//mysql连接字符串(升级EFCore3.1到时已将mysql连接字符串修改,2019-12-20)
22-
// "DbConnectionString": " Data Source=127.0.0.1;Database=netcoredev;User ID=root;Password=123456;allowPublicKeyRetrieval=true;pooling=true;CharSet=utf8;port=3306;sslmode=none;",
22+
"DbConnectionString": " Data Source=120.53.251.208;Database=netcoredev1;AllowLoadLocalInfile=true;User ID=root;Password=jxx!@#123..errrewJXXX;allowPublicKeyRetrieval=true;pooling=true;CharSet=utf8;port=3306;sslmode=none;",
2323

2424
//PgSql连接字符串
2525
// "DbConnectionString": "Host=132.232.2.109;Port=5432;User id=postgres;password=jxx_abcd;Database=netcoredev;",
@@ -36,7 +36,7 @@
3636
},
3737
//================跨域请求 (CORS)配置(2019-12-20新增),
3838
//================.netcore3.1必须配置此属性,多个url用豆号隔开,url为vue站点的地址,可以将发布后的地址也同时配置上
39-
"CorsUrls": "http://localhost:8081,http://localhost:8080,http://127.0.0.1:8081,http://127.0.0.1:8080,http://132.232.2.109,http://www.volcore.xyz",
39+
"CorsUrls": "http://localhost:8081,http://localhost:8080,http://localhost:7080,http://127.0.0.1:8081,http://127.0.0.1:7080,http://127.0.0.1:8080,http://132.232.2.109,http://www.volcore.xyz",
4040
"ExpMinutes": "120", //JWT有效期(分钟=默认120),
4141
"CreateMember": { //对表插入数据时,需要记录创建人/创建时间/创建日期,配置UserIdField/UserNameField/DateField分别为对应数据库的创建人CreateID,创建人Creator,创建时间CreateDate字段(新建数据时,由框架默认完成给这几个字段赋值,字段区分大小写)或可手动调用T.SetCreateDefaultVal()完成设置创建人/创建时间/创建日期
4242
//如果表的主键是GUID,界面查询时默认会用到DateField对应的实体(数据库)字段进行排序

开发版dev/Vue.NetCore/Vue.Net/VOL.Core/Dapper/SqlDapper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ private int MySqlBulkInsert(DataTable table, string tableName, string fileName =
450450
FileName = path.ReplacePath(),
451451
NumberOfLinesToSkip = 0,
452452
TableName = tableName,
453+
CharacterSet = "UTF8"
453454
};
454455
bulk.Columns.AddRange(table.Columns.Cast<DataColumn>().Select(colum => colum.ColumnName).ToList());
455456
insertCount = bulk.Load();

0 commit comments

Comments
 (0)