Visual Studio 服务器资源管理器未关闭 sqlsrvr.exe 进程

Visual Studio Server Explorer not closing sqlsrvr.exe process

我有这个 'issue' 很久了,我真的很想知道这是否只是我,或者是否真的有办法防止以下情况:

已更新 在 Visual Studio 中,当在 .mdf 数据库上使用服务器资源管理器时,每当我手动打开数据库以查看某些 table 的数据时,在 Entity Framework 代码优先方法项目中(单击在显示 table 数据上),似乎即使我这样关闭连接:

数据库连接在后台以某种方式保持打开状态。 如果想在关闭连接后进行调试,甚至在重新启动解决方案时,我都会收到“...数据库当前正在使用...”错误。

当我关闭任务管理器中的所有 sqlservr.exe 个进程时,它就成功了。

请注意,这是我用于测试目的的本地解决方案和本地数据库 (.mdf)。没有人或没有其他人在使用此解决方案。

我很确定这不是它应该有的行为,对吗? 如果这不是默认情况,我做错了什么或者我该怎么做才能避免这种行为?

提前感谢您的任何反馈!

在设置为 false 的连接字符串中包含“Pooling”标志:

Pooling=False

但是,这可能不是生产环境中的最佳选择:

Connection pooling reduces the number of times that new connections must be opened. The pooler maintains ownership of the physical connection. It manages connections by keeping alive a set of active connections for each given connection configuration. Whenever a user calls Open on a connection, the pooler looks for an available connection in the pool. If a pooled connection is available, it returns it to the caller instead of opening a new connection. When the application calls Close on the connection, the pooler returns it to the pooled set of active connections instead of closing it. Once the connection is returned to the pool, it is ready to be reused on the next Open call. (...) SQL Server Connection Pooling (ADO.NET)