c# - 从 SQL Server 加载数据时 C# WCF 服务随机崩溃
问题描述
我有一个 .Net framework 4.7 WCF 服务,它在开发环境和我们大多数客户的生产环境中都能正常工作,除了一个客户端。该服务在我们客户的一台服务器上随机崩溃。
该服务处理来自多个客户端应用程序的请求,其中一些请求包括执行一些复杂的 SQL 查询和从数据库加载数据。
我在客户的生产环境中使用 ProcDump 来生成故障转储,我从故障转储中获得了以下信息
Exception Analysis
MethodDesc: 00007ffc0217f420
Method Name: SNINativeMethodWrapper.SNIPacketAllocate(System.Runtime.InteropServices.SafeHandle, IOType, IntPtr ByRef)
Class: 00007ffc02168978
MethodTable: 00007ffc0217f570
mdToken: 000000000600006e
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc04facda0
Transparency: Safe critical
MethodDesc: 00007ffc021f0f10
Method Name: System.Data.SqlClient.SNIPacket..ctor(System.Runtime.InteropServices.SafeHandle)
Class: 00007ffc021d5358
MethodTable: 00007ffc021f0f30
mdToken: 000000000600224f
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc04faccc0
Transparency: Safe critical
MethodDesc: 00007ffc021f1e88
Method Name: System.Data.SqlClient.TdsParserStateObject.SendAttention(Boolean)
Class: 00007ffc021d5548
MethodTable: 00007ffc021f2160
mdToken: 00000000060022bc
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc05795b10
Transparency: Safe critical
MethodDesc: 00007ffc021f1d98
Method Name: System.Data.SqlClient.TdsParserStateObject.ReadSniError(System.Data.SqlClient.TdsParserStateObject, UInt32)
Class: 00007ffc021d5548
MethodTable: 00007ffc021f2160
mdToken: 00000000060022ad
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc07dc6b00
Transparency: Safe critical
MethodDesc: 00007ffc021f1d38
Method Name: System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
Class: 00007ffc021d5548
MethodTable: 00007ffc021f2160
mdToken: 00000000060022a7
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc04faeaf0
Transparency: Safe critical
MethodDesc: 00007ffc021f1d18
Method Name: System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
Class: 00007ffc021d5548
MethodTable: 00007ffc021f2160
mdToken: 00000000060022a5
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc04fae9f0
Transparency: Safe critical
MethodDesc: 00007ffc021f1b88
Method Name: System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer()
Class: 00007ffc021d5548
MethodTable: 00007ffc021f2160
mdToken: 000000000600228c
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc04fb38b0
Transparency: Safe critical
MethodDesc: 00007ffc021f1be8
Method Name: System.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte ByRef)
Class: 00007ffc021d5548
MethodTable: 00007ffc021f2160
mdToken: 0000000006002292
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc04fb3820
Transparency: Safe critical
MethodDesc: 00007ffc021ed6c8
Method Name: System.Data.SqlClient.TdsParser.TryRun(System.Data.SqlClient.RunBehavior, System.Data.SqlClient.SqlCommand, System.Data.SqlClient.SqlDataReader, System.Data.SqlClient.BulkCopySimpleResultSet, System.Data.SqlClient.TdsParserStateObject, Boolean ByRef)
Class: 00007ffc021d3f08
MethodTable: 00007ffc021ee3c8
mdToken: 0000000006002147
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc04fb2660
Transparency: Safe critical
MethodDesc: 00007ffc021cf7a0
Method Name: System.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean ByRef)
Class: 00007ffc021d0190
MethodTable: 00007ffc021e0068
mdToken: 0000000006001c31
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc05009b10
Transparency: Safe critical
MethodDesc: 00007ffc021cf7f8
Method Name: System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean, Boolean ByRef)
Class: 00007ffc021d0190
MethodTable: 00007ffc021e0068
mdToken: 0000000006001c38
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc050095b0
Transparency: Safe critical
MethodDesc: 00007ffc021cf7f0
Method Name: System.Data.SqlClient.SqlDataReader.Read()
Class: 00007ffc021d0190
MethodTable: 00007ffc021e0068
mdToken: 0000000006001c37
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc05009330
Transparency: Safe critical
MethodDesc: 00007ffc021cddd8
Method Name: System.Data.Common.DataAdapter.FillLoadDataRow(System.Data.ProviderBase.SchemaMapping)
Class: 00007ffc021afb48
MethodTable: 00007ffc021cdec0
mdToken: 0000000006002d0e
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc050dafd0
Transparency: Safe critical
MethodDesc: 00007ffc021cddb8
Method Name: System.Data.Common.DataAdapter.FillFromReader(System.Data.DataSet, System.Data.DataTable, System.String, System.Data.ProviderBase.DataReaderContainer, Int32, Int32, System.Data.DataColumn, System.Object)
Class: 00007ffc021afb48
MethodTable: 00007ffc021cdec0
mdToken: 0000000006002d0c
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc050d83e0
Transparency: Safe critical
MethodDesc: 00007ffc021cddb0
Method Name: System.Data.Common.DataAdapter.Fill(System.Data.DataTable[], System.Data.IDataReader, Int32, Int32)
Class: 00007ffc021afb48
MethodTable: 00007ffc021cdec0
mdToken: 0000000006002d0b
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc050d7b70
Transparency: Safe critical
MethodDesc: 00007ffc021ce4e0
Method Name: System.Data.Common.DbDataAdapter.FillInternal(System.Data.DataSet, System.Data.DataTable[], Int32, Int32, System.String, System.Data.IDbCommand, System.Data.CommandBehavior)
Class: 00007ffc021afce0
MethodTable: 00007ffc021ce6e8
mdToken: 0000000006002f80
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc050d7200
Transparency: Safe critical
MethodDesc: 00007ffc021ce4d8
Method Name: System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable[], Int32, Int32, System.Data.IDbCommand, System.Data.CommandBehavior)
Class: 00007ffc021afce0
MethodTable: 00007ffc021ce6e8
mdToken: 0000000006002f7f
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc050d6e30
Transparency: Safe critical
MethodDesc: 00007ffc021ce4b0
Method Name: System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable)
Class: 00007ffc021afce0
MethodTable: 00007ffc021ce6e8
mdToken: 0000000006002f7c
Module: 00007ffbfff78fe0
IsJitted: yes
CodeAddr: 00007ffc050d69e0
Transparency: Safe critical
我使用下面的方法从数据库加载数据,似乎崩溃总是发生在 DataAdapter.Fill
private DataTable LoadDataTable(string Command, int? TimeoutOverride)
{
var dt = new DataTable();
try
{
using (m_ActiveCommand = new SqlCommand(Command, Connection as SqlConnection))
{
using (var ad = new SqlDataAdapter(m_ActiveCommand))
{
ad.SelectCommand.CommandTimeout = TimeoutOverride ?? Timeout;
ad.Fill(dt);
}
}
}
catch (Exception ex)
{
LogHelper.WriteToLog(ex);
return null;
}
return dt;
}
解决方案
推荐阅读
- c - 在 C 编程中需要生成 4 个不重复的随机数。1到4
- python - 如何知道 python 中的程序是否在 spyder 中运行?
- omnet++ - 动脉(VEINS 扩展)- LTE 和 IEEE 802.11p 结合
- python - 从 python 类中的另一个方法访问在方法内部创建的变量
- javascript - 使用对象数组展平对象中的数据
- java - 如何在原生 android 和 java 中查找嵌套元素
- tsql - TSQL:尝试简化/优化我的存储过程
- r - 是否有像 ggplot 或 plot 之类的 R 函数以按 id 和不同颜色在同一图中显示我所有的时间序列曲线
- c# - 获取 XML 正文 - 调用肥皂网络服务时出现反序列化错误
- apache-spark - 使用 Spark 从 S3 复制到 HDFS