首页 新闻 会员 周边 捐助

各位大神Thread was being aborted

0
悬赏园豆:5 [待解决问题]

System.Threading.ThreadAbortException: Thread was being aborted.
   at SNIReadSyncOverAsync(SNI_ConnWrapper* , SNI_Packet** , Int32 )
   at SNINativeMethodWrapper.SNIReadSyncOverAsync(SafeHandle pConn, IntPtr& packet, Int32 timeout)
   at System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
   at System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
   at System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer()
   at System.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte& value)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   at System.Data.SqlClient.SqlDataReader.get_MetaData()
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   at WebSite.BizAG.NABillingSplitTask.BillingSplitTaskMain.ExecuteDatatable(SqlConnection connection, CommandType commandType, String commandText, SqlParameter[] commandParameters)
   at WebSite.BizAG.NABillingSplitTask.BillingSplitTaskMain.ExecuteDatatable(String connectionString, CommandType commandType, String commandText, SqlParameter[] commandParameters)
   at WebSite.BizAG.NABillingSplitTask.BillingSplitTaskMain.WhileMainExecute()

 

帮帮看看是啥引起的,我怀疑是SqlBulkCopy类引起的。这是截图

using (SqlConnection sqlConnection = new SqlConnection(connectionString))
                {
                    sqlConnection.Open();
                    SqlTransaction sqlTransaction = sqlConnection.BeginTransaction();
                    try
                    {
                        using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(sqlConnection, SqlBulkCopyOptions.TableLock, sqlTransaction))
                        {
                            sqlBulkCopy.BatchSize = batchSize;
                            sqlBulkCopy.BulkCopyTimeout = 3000;
                            sqlBulkCopy.DestinationTableName = tableName;
                            for (int i = 0; i < table.Columns.Count; i++)
                            {
                                sqlBulkCopy.ColumnMappings.Add(table.Columns[i].ColumnName, table.Columns[i].ColumnName);
                            }
                            sqlBulkCopy.WriteToServer(table);
                            sqlTransaction.Commit();
                        }
                        return true;
                    }
                    catch (Exception ex)
                    {
                        myex = ex;
                        sqlTransaction.Rollback();
                        f = true;
                    }
                }

 

小奉手的主页 小奉手 | 初学一级 | 园豆:148
提问于:2016-12-15 10:19
< >
分享
所有回答(1)
0

看起来像超时了,你增加超时时间试试。

Daniel Cai | 园豆:10424 (专家六级) | 2016-12-15 10:26

突然想起来我只改了本地,没有发布。但是Thread was being aborted为什么有线程被终止呢。是SqlBulkCopy这个引起的吗

支持(0) 反对(0) 小奉手 | 园豆:148 (初学一级) | 2016-12-15 10:29

@小奉手: 

 SNIReadSyncOverAsync方法内有个timeout的参数,再往里就是extern方法了,因此感觉是因为timeout

支持(0) 反对(0) Daniel Cai | 园豆:10424 (专家六级) | 2016-12-15 10:36

@Daniel Cai: 因为我执行数据库的链接的地方就只有上面问题中的代码段和下面图的两个,这两个都有try,但是这个错误的记录到了调用这个两个方法的那个主方法的try中了,好奇怪

支持(0) 反对(0) 小奉手 | 园豆:148 (初学一级) | 2016-12-15 11:03

今天复现了这个错误,其实报的是这个,但是不知为何记录的错误是上面问题的错误。报错的原因应该是配置文件里设置的导致的

支持(0) 反对(0) 小奉手 | 园豆:148 (初学一级) | 2016-12-15 17:25

@小奉手: asp.net请求处理时基于线程池中的线程的,而请求一旦超时只有通过thread.abort方式终止执行,因此你那里抛出来的是threadabortexception

支持(0) 反对(0) Daniel Cai | 园豆:10424 (专家六级) | 2016-12-16 13:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册