SQL Server SPID 和事务范围
我们正在使用实体框架在事务范围内对 SQL Server 数据库运行多次调用。
我们假设 SPID 将在事务处理期间保留并且所有调用都将在同一个 SPID 上进行,这样假设正确吗?
We are running several calls against a SQL Server database within a transaction scope using entity framework.
Are we right is assuming that the SPID will be held for the duration of the transaction and that all calls will be made on the same SPID?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们发现SPID连接到一个连接,而不是一个事务。
但 EF 将关闭并打开连接,以便将其纳入事务中。
连接实际上并未关闭,而是被释放到连接池中,然后再次检索。
那么问题是您可能无法从连接池中获取相同的连接,在这种情况下您将不会拥有相同的 SPID。
We found out that a SPID is connected to a connection, not to a transaction.
But EF will close and open a connection in order to enlist it in a transaction.
The connection is not actually closed in is released to the connection pool and then retrieved again.
The problem is then that you may not get the same connection back from the connection pool, in which case you will not have the same SPID.
是的,SPID 在交易期间将保持不变。
Yes, the SPID will be the same for the duration of the transaction.