我正在编写一个.NET应用程序,它使用Entity Framework将数据写入Postgres v12数据库。应用程序本身会监视文件系统,并在每次看到更改时将数据写入数据库。
数据本身既是插入又是更新,分布在多个表中。
到目前为止,这是有效的-大部分时间。
然而,程序经常挂起,停止响应。看起来要写入的数据越多,问题发生的频率就越高。
重新启动应用程序后,有时它工作,有时它不工作。
实际挂起发生在调用
DbContext.SaveChanges
然后在Postgres日志中,我发现了一个条目:
错误:无法从客户端接收数据:无法识别的winsock错误10054
:来自客户端的不完整消息(翻译自德语)
错误:无法从客户端接收数据:无法识别的winsock错误10054
错误:来自客户端的消息不完整
谷歌没有帮助我的消息,它总是关于连接问题,如果你自己编程套接字。
有人知道我该怎么办吗?我可以更改Postgres的连接参数中的某些内容吗?或者从哪里开始查看?
Postgres数据库本身与我的应用程序运行在同一个系统上,挂起时的stacktrace:
[Übergang von Verwaltet zu Nativ] Annotated Frame
System.Net.Sockets.dll!System.Net.Sockets.SocketPal.Receive(System.Net.Sockets.SafeSocketHandle handle, System.Span<byte> buffer, System.Net.Sockets.SocketFlags socketFlags, out int bytesTransferred) Unknown Non-user code. Skipped loading symbols.
System.Net.Sockets.dll!System.Net.Sockets.Socket.Receive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode) Unknown Non-user code. Skipped loading symbols.
System.Net.Sockets.dll!System.Net.Sockets.NetworkStream.Read(byte[] buffer, int offset, int size) Unknown Non-user code. Skipped loading symbols.
Npgsql.dll!Npgsql.NpgsqlReadBuffer.Ensure.__EnsureLong|40_0(Npgsql.NpgsqlReadBuffer buffer, int count, bool async, bool readingNotifications) Unknown Non-user code. Skipped loading symbols.
Npgsql.dll!Npgsql.NpgsqlConnector.ReadMessage.__ReadMessageLong|194_0(Npgsql.NpgsqlConnector connector, bool async, Npgsql.DataRowLoadingMode dataRowLoadingMode, bool readingNotifications, bool isReadingPrependedMessage) Unknown Non-user code. Skipped loading symbols.
Npgsql.dll!Npgsql.NpgsqlConnector.ReadMessage(bool async, Npgsql.DataRowLoadingMode dataRowLoadingMode, bool readingNotifications) Unknown Non-user code. Skipped loading symbols.
Npgsql.dll!Npgsql.NpgsqlDataReader.NextResult(bool async, bool isConsuming, System.Threading.CancellationToken cancellationToken) Unknown Non-user code. Skipped loading symbols.
Npgsql.dll!Npgsql.NpgsqlDataReader.NextResult() Unknown Non-user code. Skipped loading symbols.
Npgsql.dll!Npgsql.NpgsqlCommand.ExecuteReader(System.Data.CommandBehavior behavior, bool async, System.Threading.CancellationToken cancellationToken) Unknown Non-user code. Skipped loading symbols.
Npgsql.dll!Npgsql.NpgsqlCommand.ExecuteReader(System.Data.CommandBehavior behavior) Unknown Non-user code. Skipped loading symbols.
Npgsql.dll!Npgsql.NpgsqlCommand.ExecuteDbDataReader(System.Data.CommandBehavior behavior) Unknown Non-user code. Skipped loading symbols.
System.Data.Common.dll!System.Data.Common.DbCommand.ExecuteReader() Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.Relational.dll!Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(Microsoft.EntityFrameworkCore.Storage.RelationalCommandParameterObject parameterObject) Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.Relational.dll!Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(Microsoft.EntityFrameworkCore.Storage.IRelationalConnection connection) Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.Relational.dll!Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(System.Collections.Generic.IEnumerable<Microsoft.EntityFrameworkCore.Update.ModificationCommandBatch> commandBatches, Microsoft.EntityFrameworkCore.Storage.IRelationalConnection connection) Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.Relational.dll!Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(System.Collections.Generic.IList<Microsoft.EntityFrameworkCore.Update.IUpdateEntry> entries) Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(System.Collections.Generic.IList<Microsoft.EntityFrameworkCore.Update.IUpdateEntry> entriesToSave) Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Microsoft.EntityFrameworkCore.DbContext _, bool acceptAllChangesOnSuccess) Unknown Non-user code. Skipped loading symbols.
Npgsql.EntityFrameworkCore.PostgreSQL.dll!Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute<bool, int>(bool state, System.Func<Microsoft.EntityFrameworkCore.DbContext, bool, int> operation, System.Func<Microsoft.EntityFrameworkCore.DbContext, bool, Microsoft.EntityFrameworkCore.Storage.ExecutionResult<int>> verifySucceeded) Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(bool acceptAllChangesOnSuccess) Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.DbContext.SaveChanges(bool acceptAllChangesOnSuccess) Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.DbContext.SaveChanges() Unknown Non-user code. Skipped loading symbols.
> SPCDataWriterWorker.dll!Promess.MeasurementResults.SPCDataWriterWorker.Globals.SaveDBChangesWithEvent(Promess.MeasurementResults.Model.ResultContext db, string sTablename) Line 56 C# Symbols loaded.
引用的软件包:
- EF Core 5.0.7
- NodaTime 3.0.3
- Npqsql 5.0.6
SaveDBChangesWithEvent
就是:
internal static void SaveDBChangesWithEvent(ResultContext db, string sTablename)
{
if (!db.ChangeTracker.AutoDetectChangesEnabled)
{
db.ChangeTracker.DetectChanges();
}
int iSavedRowCount = db.SaveChanges();
Debug.Trace($"{iSavedRowCount} geänderte Datensätze in {sTablename}");
Globals.FireProcessFileStep(string.Format(
Texts.ProcessStepWriteDBChangeCount, iSavedRowCount, sTablename), Globals.EventsSeverity.Debug);
}
1条答案
按热度按时间oxiaedzo1#
看起来在更新引用的包后错误确实消失了。我将进一步研究它,并在它再次发生时发布一个更完整的示例。感谢大家