C# 数据库写入Sql Bulk索引损坏异常问题

System.InvalidOperationException: DataTable internal index is corrupted: '4'

这几天发现数据库写入时报了这样的一个异常出来,之前从未出现过的,网上搜索了一下,多数是提到4个原因:

引用自:https://stackoverflow.com/questions/450675/datatable-internal-index-is-corrupted

Here are  reasons that I know how DataTable internal index is corrupted: '' happens.

)      Changing values during DataView.ListChanged event. This is not supported.

Look at the callstack and if you see DataView.OnListChanged and you are changing a DataRow/Set/Table, then index corruption will likely happen (i.e. thrown from DataRow.EndEdit)

Short description of the problem: the internal indexes getting notified of the edits out-of-order.

Workaround - use the DataTable.RowChanged event instead of the DataView.ListChanged.

)      There is still an unfixed bug when merging data into an existing DataRow that starts in the Added or Deleted state and ends in the Modified row state.

DataAdapter.Fill, DataSet.Load, DataTable.Load when LoadOption.PreserveChanges.

DataSet.Merge, DataTable.Merge deleted rows.

DataSet.Merge(DataRow[]) for added rows.

Short description of the problem: The DataTable tells the DataView to “add” instead of “change”, resulting in index corruption.

)      multi-threading

The DataSet/DataTable and any connected objects are not thread safe.  Make sure you lock all the appropriate objects.

)      When the DataColumn.DataType is a reference type and the values are being changed instead of being treated as read only.
Example: DataColumn.DataType is byte[] and the column sorted. If the values in the byte array are changed instead of assigning a new byte array to the DataRow, the internal index doesn’t know about the change and becomes corrupt. This is data being changed without the internal index being notified.

因为我的代码用了多线程,猜测可能是由于这个原因,但是通过写测试代码测试,1000个线程不加锁来写,也没有这样问题存在。

折磨了几天后,又仔细看了下异常信息,用再接近报错代码的地方的信息搜索了下

at System.Data.RBTree`1.GetNewNode(K key)
at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean suppressEnsurePropertyChanged, Int32 position, Boolean fireEvent, Exception& deferredException)
at System.Data.DataTable.InsertRow(DataRow row, Int64 proposedID, Int32 pos, Boolean fireEvent)

发面,按这个搜索的结果,就是和内存相关了,OutOfMemoryException,于是运行程序看了下内存,终于发现问题了,跑到高峰时,内存暴满了。

http://www.databaseforum.info/1/1/ec1879c1a0b65ca3.html

瀑汗啊!! 原来是内存崩溃造成的索引损坏!

C# 数据库写入Sql Bulk索引损坏异常问题System.InvalidOperationException: DataTable internal index is corrupted: '4'的更多相关文章

  1. 异常:System.InvalidOperationException: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms FIPS信息标准限值了MD5加密

    最近做的winform项目中,有个功能使用了MD5 加密,本地测试是没有问题的,但是上线后有些用户反馈说提示如下错误 一.问题描述 中文版错误截图 英语版错误截图 具体错误信息: 有关调用实时(JIT ...

  2. 异常:System.InvalidOperationException: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms 这个实现是不是Windows平台FIPS验证的加密算法。解决方法

    遇见这个问题是在使用了MD5加密算法后报错的,可能的原因如下: 1.FIPS不兼容MD5,此时需要修改注册表 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\C ...

  3. EF异常:“System.InvalidOperationException”类型的未经处理的异常在 mscorlib.dll 中发生

     实体框架System.Data.Entity.SqlServer提供者类型”. SqlProviderServices EntityFramework. 的在应用程序配置文件注册状态"置疑 ...

  4. 关于DataTable内部索引已损坏的问题 System.Data.RBTree

    1.错误提示: 最近,Winform程序在极其偶然的情况下会遇到如下错误提示 Framework 版本: v4.0.30319 说明: 由于未经处理的异常,进程终止. 异常信息: System.Inv ...

  5. redis数据库写入数据时提示redis.exceptions.ResponseError错误

    今天运行Django项目在redis数据库写入数据时提示如下错误: ERROR log 228 Internal Server Error: /image_code/cf9ccd75-d274-45c ...

  6. sql2005数据库置疑修复断电崩溃索引损坏 数据库索引错误修复/数据库表损坏/索引损坏/系统表混乱等问题修复

    sql2005数据库置疑修复断电崩溃索引损坏 数据库索引错误修复/数据库表损坏/索引损坏/系统表混乱等问题修复 客 户 名 称 济南某电子商务公司 数 据 类 型 SQL2005数据库 故 障 检 测 ...

  7. SQL 撤销索引、表以及数据库

    通过使用 DROP 语句,可以轻松地删除索引.表和数据库. SQL DROP INDEX 语句 我们可以使用 DROP INDEX 命令删除表格中的索引. 用于 Microsoft SQLJet (以 ...

  8. SQL 撤销索引、撤销表以及撤销数据库

    SQL 撤销索引.撤销表以及撤销数据库 通过使用 DROP 语句,可以轻松地删除索引.表和数据库. DROP INDEX 语句 DROP INDEX 语句用于删除表中的索引. 用于 MS Access ...

  9. [SQL SERVER] - 还原数据库备份(SQL脚本),抛出 "System.OutOfMemoryException" 异常之解决

    背景 在 Microsoft SQL Server 2016 的查询窗体中,直接还原备份数据库的 SQL 脚本(99MB),抛出 Cannot execute script 异常: 原因 相关资料说: ...

随机推荐

  1. bootstrap 警告(Alerts)

    本章将讲解警告(Alerts)以及bootstrap所提供的用于警告的class类.警告(Alerts)向用户提供了一种定义消息样式的方式.它们为典型的用户操作提供了上下文信息反馈. 您可以为警告框添 ...

  2. NSRegularExpression 使用

    需求: // 后台返回的某个实体 reminder = { cost = , type = , template = 可免费做某事{time}分钟,超过将按{cost}K元收费, time = } t ...

  3. ANSI C 与 K&R C

    C语言由Dennis M.Ritchie在1973年设计和实现.从那以后使用者逐渐增加.到1978年Ritchie和Bell实验室的另一位程序专家Kernighan合写了著名的<TheC Pro ...

  4. Linux菜鸟起飞之路【七】文件合并、归档和压缩

    一.文件合并操作 1.覆盖符号与追加符号 a)“>”代表将左边文件的内容覆盖右边文件的内容,如果右边文件不存在则创建这个文件 b)“>>”代表将左边文件的内容追加到右边文件中,如果右 ...

  5. 【mysql】【转发】my.cnf 讲解

    PS:本配置文件针对Dell R710,双至强E5620.16G内存的硬件配置.CentOS 5.6 64位系统,MySQL 5.5.x 稳定版.适用于日IP 50-100w,PV 100-300w的 ...

  6. ultraedit编辑器破解版下载

    ultraedit一款功能丰富的网站建设软件,需要的朋友可以看看. 百度百科:UltraEdit 是一套功能强大的文本编辑器,可以编辑文本.十六进制.ASCII 码,完全可以取代记事本(如果电脑配置足 ...

  7. win10安装pytorch——前面有坑,快跳进去鸭

    嗯!花费了不少时间才把pytorch安装成功.主要原因就是: 清华和中科大的Anaconda国内镜像源关闭了 activate.bat 不是内部或外部命令(这个真实奇怪) 1. 安装过程 可以去Ana ...

  8. python并发编程之线程(创建线程,锁(死锁现象,递归锁),GIL锁)

    什么是线程 进程:资源分配单位 线程:cpu执行单位(实体),每一个py文件中就是一个进程,一个进程中至少有一个线程 线程的两种创建方式: 一 from threading import Thread ...

  9. 持续化集成Jenkins的系统配置

    最近在研究selenium2自动化测试,用到持续化集成jenkins.由于之前仅限于使用,而没有真正动手配置过,所以现在学习从零开始,搭建持续化集成,故而有了这篇博客. 先介绍一下项目持续集成测试,这 ...

  10. [转] 在vue中使用SockJS实现webSocket通信

    最近接到一个业务需求,需要做一个聊天信息的实时展示的界面,这就需要和服务器端建立webSocket连接,从而实现数据的实时获取和视图的实时刷新.在此将我的实现记录下来,希望可以给有同样需求的人一些帮助 ...