> For the complete documentation index, see [llms.txt](https://monksoul.gitbook.io/hoa/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://monksoul.gitbook.io/hoa/shujukucaozuoshinan/dbchangjiancuowu.md).

# 9.15、常见错误

对于新手，刚接触 EF Core 操作难免会出现一些比较常见的错误。

## 查询忘记调用 \`ToList()\` 方法，提示数据库已被释放。

在 `EF Core` 中，只有调用 `ToList()`，或者遍历结果集（`for`，`foreach`）才会执行真正的Sql查询，否则只是在构建Sql语句，不会执行真正查询。

## There is already an open DataReader associated with this Connection which must be closed first.

执行SqlDataReader.Read之后，如果还想用另一个SqlCommand执行Insert或者Update操作的话，会得到一个错误提示：**There is already an open DataReader associated with this Command which must be closed first**.，然后一般就会产生数据保存失败的异常。

解决方法是在ConnectionString中加上一个参数“MultipleActiveResultSets”, 将其值设置为true。

```
server=s01;database=MOULTONWEB;uid=sa;pwd=cn1234567890;MultipleActiveResultSets=True;
```
