在不指定事务的情况下执行 SQLCommand [英] Executing an SQLCommand without specifying a Transaction
问题描述
我们通过 SqlCommand 对 SQL Server 数据库执行 SELECT
查询,在我们的应用程序中获取了一些数据列表.我们没有在 SqlCommand 上显式设置事务,而只是向它传递一个 SqlConnection 并运行它.是不是在没有指定事务的情况下,SQL Server 会启动并使用一个默认的事务,默认的IsolationLevel 为ReadCommitted
?
We have some lists of data being fetched in our application via a SqlCommand performing a SELECT
query on a SQL Server database. We do not explicitly setup a transaction on the SqlCommand, instead just passing it a SqlConnection and running it. Is it the case that when no transaction is specified that SQL Server will initiate and use a default transaction with the default IsolationLevel of ReadCommitted
?
推荐答案
SQL Server 可以在没有显式事务的情况下愉快地工作.但是,是的,我相信它本质上是读提交的(当然,除非您向查询对象添加额外的提示,例如 UPDLOCK
/NOLOCK
).您可以通过以下方式对此进行调查:
SQL Server can work happily without an explicit transaction. But yes, I believe it is essentially read-committed (unless, of course, you add extra hints to your query objects,such as UPDLOCK
/ NOLOCK
). You can investigate this with:
DBCC USEROPTIONS
其中显示(以及其他):
which shows (among others):
isolation level read committed
这篇关于在不指定事务的情况下执行 SQLCommand的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!