gpt4 book ai didi

c# - 无法弄清楚异常消息

转载 作者:行者123 更新时间:2023-11-30 13:12:17 25 4
gpt4 key购买 nike

我收到以下错误消息,我正在使用 petaPOCO。为什么我会收到此错误消息以及收到此消息我做错了什么:

{"There is already an open DataReader associated with this Command which must be closed first."}

This is what I have been able to copy for the exception message.

System.InvalidOperationException was caught Message=There is already an open DataReader associated with this Command which must be closed first. Source=System.Data StackTrace: at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command) at System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command) at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteScalar() at PetaPoco.Database.Insert(String tableName, String primaryKeyName, Boolean autoIncrement, Object poco) in C:\Dev\Code\API\Models\PetaPoco.cs:line 1243 InnerException:

最佳答案

我知道这是旧的,但我想添加一些可能有助于下一个搜索此内容的人。如果您使用 Query 方法,则会发生此错误。 Query 方法不会将所有内容加载到内存中。如果您需要加载它然后关闭连接,则需要使用 Fetch。

这是来自网站:

Query vs Fetch

The Database class has two methods for retrieving records Query and Fetch. These are pretty much identical except Fetch returns a List<> of POCO's whereas Query uses yield return to iterate over the results without loading the whole set into memory.

希望这对其他人有帮助。

关于c# - 无法弄清楚异常消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9511669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com