由于批处理被中止,请求无法运行,这可能是由客户端发送的中止信号引起的

本文关键字:客户端 信号 运行 批处理 请求 | 更新日期: 2023-09-27 18:29:04

在我的程序中,我使用任务并行库来减少进程的时间。我用这个代码来做这项工作。

Task[] tasks = new Task[10]
{
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 1 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 2 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 3 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 4 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 5 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 6 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 7 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 8 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 9 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 10, (e.Argument as string[])[1]))
};
Task.WaitAll(tasks);

DoFiles()方法处理一些文件,然后在数据库中的文件中插入单词。每个Task都处理一些文件。我用这个代码插入数据库:

SqlBulkCopy sbc = new SqlBulkCopy(clsGlobal.cnTashih);
sbc.DestinationTableName = "tblListTekrari_3";
sbc.BulkCopyTimeout = 0;
sbc.WriteToServer(dtT);
sbc.Close();

当我运行程序时,有时我会得到以下错误:

Cannot access destination table 'tblListTekrari_3'.
System.Data
The request failed to run because the batch is aborted, this can be caused by abort signal sent from client, or another request is running in the same session, which makes the session busy.
at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternal()
at System.Data.SqlClient.SqlBulkCopy.WriteRowSourceToServer(Int32 columnCount)
at System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table, DataRowState rowState)
at System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table)
at tashih.frmStart.DoFiles(Int32 countFull, Int32 NotCountFull, Int32 part, String ProjectID)

有人能帮我吗?

由于批处理被中止,请求无法运行,这可能是由客户端发送的中止信号引起的

使用并行批量复制将数据复制到特定分区

使用并行大容量复制将数据并行复制到特定分区。并行大容量复制大大提高了bcp会话期间的性能,因为它可以将大型大容量复制作业拆分为多个会话并同时运行这些会话。

要使用并行批量复制:

  • 必须对目标表进行分区

请使用sp_helpartition查看表上的分区数。

使用alter表。。。partition,如果表尚未分区,则对表进行分区。

  • 目标表不应包含索引,因为:

如果表具有聚集索引,则该索引将确定数据的物理位置,从而导致bcp命令中的分区规范被忽略。

如果存在任何索引,bcp会自动使用其慢速大容量复制模式,而不是快速大容量复制方式。

  • 如果表上存在非聚集索引,则并行大容量复制可能会导致索引页上的死锁
  • 每个分区都应该位于一个单独的物理磁盘上,以获得最佳效果性能
  • 在将数据复制到数据库中之前,请对指定的表进行分区以包含数据
  • 并行大容量复制可以从多个操作复制到表中系统文件

对于所有类型的分区表,请使用:

文件名中的bcp表名分区分区名

仅对于循环分区表,请使用:

文件名中的bcp表名partition_number