我正在使用带有 SignalR 的 EFCore SQLite。
当有多个客户端同时连接时,数据库无法再更改(插入/更新),此异常抛出:“无法回滚 - 没有事务处于活动状态”
客户端与包含其信息的查询参数连接,然后:
- 查看数据库,如果 clientName 存在,则更新其信息。否则,添加新的。
- 连接后,客户端名称调用 GetData() 返回所有客户端信息等...
- 大约有 100 个客户端同时连接。
日志:
An exception occurred in the database while iterating the results of a query.
System.InvalidOperationException: A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe.
然后
Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 5: 'database is locked'.
之后,当我尝试插入或更新内容时:
Cannot rollback - No transaction is active
有解决方法吗?这仅发生在具有 50 个以上客户端的生产环境中,因此在开发时很难调试。
任何帮助将不胜感激!