首页 > 解决方案 > 从 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#sql-serverwcfado.net

解决方案


推荐阅读