- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试找出是哪一列或哪些列触发了以下错误。由第 3 方服务提供的传入数据发生了一些变化,现在当我尝试将其保存到 SQL 时导致失败。
Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Arithmetic overflow error converting numeric to data type numeric. The statement has been terminated.
一个非常简单的流程:
数据结构定义为:
[JsonObject(MemberSerialization.OptIn)]
public class RatDbAttributes
{
[JsonProperty]
[StringLength(50)]
public string block_chain { get; set; } // varchar(50)
[JsonProperty]
[StringLength(50)]
public string block_reduction { get; set; } // varchar(50)
[JsonProperty]
[StringLength(50)]
public string block_reward { get; set; } // varchar(50)
[JsonProperty]
public double block_time { get; set; } // decimal(28,6)
[JsonProperty]
[StringLength(100)]
public string consensus_method { get; set; } // varchar(100)
[JsonProperty]
public decimal decimals { get; set; } // decimal(28,6)
[JsonProperty]
[StringLength(50)]
public string difficulty_retarget { get; set; } // varchar(50)
[JsonProperty]
[StringLength(200)]
public string genesis_address { get; set; } // varchar(200)
[JsonProperty]
[StringLength(100)]
public string hash_algorithm { get; set; } // varchar(100)
[JsonProperty]
[StringLength(50)]
public string mineable { get; set; } // varchar(50)
[JsonProperty]
public long p2p_port { get; set; } // bigint
[JsonProperty]
public long rpc_port { get; set; } // bigint
[JsonProperty]
[StringLength(200)]
public string token_role { get; set; } // varchar(200)
[JsonProperty]
public decimal @float { get; set; } // decimal(28,6)
[JsonProperty]
public decimal minted { get; set; } // decimal(28,6)
[JsonProperty]
public decimal total_supply { get; set; } // decimal(28,6)
[JsonProperty]
public decimal max_supply { get; set; } // decimal(28,6)
[JsonProperty]
[StringLength(133)]
public string wallet { get; set; } // varchar(133)
[JsonProperty]
[NotMapped]
public double genesis_timestamp { get; set; } // see below
[JsonIgnore]
public DateTime Genesis_TimeStamp { get { return genesis_timestamp.ToDateTime(); } set { genesis_timestamp = value.ToEpoch(); } }
// Foregin Key Relationship (1-to-1) and Primary Key
[JsonIgnore]
public long TokenMasterId { get; set; }
[JsonIgnore]
[ForeignKey("TokenMasterId")]
public RatDbTokenMaster TokenMaster { get; set; } //foreign key to Parent
}
我已经仔细检查了 genesis_timestamp
,这不是问题所在(将 double 转换为日期时间)。
示例传入的失败 JSON:
{"block_chain":""
,"block_reduction":""
,"block_reward":"0"
,"block_time":0.0
,"consensus_method":""
,"decimals":0.0
,"difficulty_retarget":""
,"genesis_address":""
,"hash_algorithm":""
,"mineable":"False"
,"p2p_port":0
,"rpc_port":0
,"token_role":""
,"float":0.0
,"minted":0.0
,"total_supply":0.0
,"max_supply":0.0
,"wallet":""
,"genesis_timestamp":0.0
}
最佳答案
我为批处理失败时创建了故障转移迭代保存。因为我为这个类(class)设置了“全局”数据库连接,所以我无意中遇到了问题。我会添加记录集并尝试保存它(错误弹出),然后尝试迭代越来越小的批处理以发现有问题的记录。问题是我在迭代之前没有删除有问题的记录集。因此,每次迭代都携带了数据库连接中的错误条件!
internal void IterateSave<TModel>(List<TModel> items) where TModel : class
{
using (LogContext.PushProperty("Data: Class", nameof(RatBaseCommandHandler)))
using (LogContext.PushProperty("Data: Method", nameof(IterateSave)))
using (LogContext.PushProperty("Data: Model", nameof(items)))
{
int max = items.Count;
int skip = 0;
int take = (max > 20) ? (max / 5) : 1;
int lastTake = take;
List<TModel> subItems = new List<TModel>();
while (skip <= max)
{
try
{
subItems = items.Skip(skip).Take(take).ToList();
Log.Verbose("Working {Max} | {Take} | {Skip}", max, take, skip);
skip += take;
_db.Set<TModel>().AddRange(subItems);
_db.SaveChanges();
}
catch (Exception ex)
{
/***** Was not removing the faulty record/recordset! *****/
_db.Set<TModel>().RemoveRange(subItems);
/***** Was not removing the faulty record/recordset! *****/
if (take == 1 && skip < max)
{
Log.Error(ex, "Error saving specific record in this data batch! {GuiltyRecord}", JsonConvert.SerializeObject(subItems));
if (skip >= max - 1)
{
depth--;
return;
}
}
else if (take > 1)
{
Log.Warning("Something is wrong saving this data batch! {RecordCount} Running a smaller batch to isolate.", take);
IterateSave(subItems);
}
}
}
}
}
添加了这两行(catch 中的注释部分),错误立即弹出!
Error saving specific record in this data batch! "[{\"block_chain\":\"Ethereum\",\"block_reduction\":\"\",\"block_reward\":\"0\",\"block_time\":0.0,\"consensus_method\":\"\",\"decimals\":18.0,\"difficulty_retarget\":\"\",\"genesis_address\":\"0x3520ba6a529b2504a28eebda47d255db73966694\",\"hash_algorithm\":\"\",\"mineable\":\"False\",\"p2p_port\":0,\"rpc_port\":0,\"token_role\":\"\",\"float\":0.0,\"minted\":60000000000000000000000000.0,\"total_supply\":60000000000000000000000000.0,\"max_supply\":60000000000000000000000000.0,\"wallet\":\"\",\"genesis_timestamp\":0.0}]" Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Arithmetic overflow error converting numeric to data type numeric. The statement has been terminated.
虽然 C# 可以处理 DECIMAL 数据类型的 60000000000000000000000000.0,但我们的 SQL 是在 DECIMAL(28,6) 定义的。由于 6 位精度只为 10^22 值留出空间。
(看来 SQL 现在可以处理 DECIMAL(38,6)。是时候在不丢失生产数据的情况下使用列定义了。)
关于sql-server - 将数字转换为数字数据类型时出现算术溢出错误。英孚核心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56010059/
我正在尝试从 1 循环到 12,并为应用中特定 View 的更改网格输出一些跨度宽度。 $span-width: 8.21875%; $gap: 0.125%; @for $i from 1 thro
我试图在 Jekyll 的液体模板引擎中做一些基本的算术。我已经分配了一个变量 numColumns我试图在条件语句中使用它。 {% assign numColumns = 3 %} 注意我在下面的表
与 shift_left ieee.numeric_std 的功能, 我想将信号左移并插入 1或 0从右边。 signal qo: signed (3 downto 0) := (others=>'0
您在控制台中输入一些内容,例如(8+8)。然后程序会告诉你括号的插入是否正确。 这是我对错误括号的定义(当然还没有完成): () this means if one array element is
我有两个表(使用 PostgreSQL),它们看起来如下: 表1(p点从1到450递增1) --------+-------+--------+---------+---------+-------+
我正在编写一个任意精度的有理数包,我需要测试它的正确性和效率。当然,我可以自己组合一组临时测试,但由于我远不是第一个这样做的人,所以我认为值得一问:任何人都可以推荐我可以使用的现有测试集吗? 编辑:我
我最近一直在使用和学习 CSS3,并享受它的许多功能。现在我想知道是否可以设置一个有条件地分配 block 元素宽度的 CSS 规则。我所追求的那种东西 - 如果屏幕宽度小于 500 像素,则使用 3
我对这个实验中h的值有点疑惑。在 cpp 中, int h,J=3,n=200,p=3,h_m=(n+p+1)/2; float rt=(float)h_m/n; for(int j=0,j
算术+和按位或有什么区别吗?这有什么不同。 uint a = 10; uint b = 20; uint arithmeticresult = a + b; uint bitwiseOR = a |
我一直在尝试让算术 if 运算符起作用,但我似乎做不到。我是 C++ 的新手,仍在学习基础知识,但我只是想知道我是否正确使用了这个运算符。如果 x using namespace std; int
我在 VC++2010 中做过一些混合不同大小的操作数导致添加操作溢出的测试: int _tmain(int argc, _TCHAR* argv[]) { __int8 a=127;
#include int main(int argc,char *argv[]) { int i=10; void *k; k=&i; k++; printf("%p\n
在过去的 5 个小时里,我一直在寻找答案。尽管我找到了很多答案,但它们并没有以任何方式提供帮助。 我基本上要寻找的是任何 32 位无符号整数的按位异或运算符的数学、算术唯一表示。 尽管这听起来很简单,
结果是 127 double middle = 255 / 2 虽然这产生了 127.5 Double middle = 255 / 2 同时这也会产生 127.5 double middle = (
我在 Java 1.7 中有以下代码: DateFormat df = DateFormat.getInstance(); Date startDate = df.parse("07/28/12 01
此查询有效,没有错误 select add_months(date '2011-01-31', 1) from dual; ,而这个: select date '2011-01-31' + inter
理论上来说,如果我有一个无序项目列表 Link1 Link1 我如何使用 jQuery 执行以下操作? 1) 找到每个单独a元素的宽度 2) 找到每个单独的 li 元素的宽度 3)
想法如下:假设我有一个列表 P = [(1,0),(4,3)] 或类似的列表。我想以以下方式计算此列表定义的多项式:1X^0 + 4X^3。 为此,我编写了以下内容: evaluate(P,X,Y)
我正在从 mysql 数据库中提取数据。我想添加多次运行的长度,并按照跑得最远的人的排名对它们进行排序。 function determineLength($db, $name){
当尝试执行一个简单的 bash 脚本以将前面带有 0 的数字递增 1 时,原始数字被错误地解释。 #!/bin/bash number=0026 echo $number echo $((number
我是一名优秀的程序员,十分优秀!