开发者

Can I set the isolation level in the connection string?

How can I set the isolation level of all my SqlCommand ExecuteNonQuery calls to be read uncommitted? (connecting to a SQL Server 2008 enterprise instance)

I am simpl开发者_运维知识库y transforming static data and inserting the results to my own tables on a regular basis, and would like to avoid writing more code than necessary.


No, you cannot.

You need to explicitly define the isolation level when you start a transaction.

For more info on adjusting the isolation level, see the MSDN documentation on the topic.


No, you cannot.

And there is No way of changing the default transaction isolation level.

http://blogs.msdn.com/b/ialonso/archive/2012/11/26/how-to-set-the-default-transaction-isolation-level-server-wide.aspx


You can set the isolation level in the SqlTransaction object, which is a property of the SqlCommand object.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqltransaction.isolationlevel.aspx


SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
BEGIN TRAN
/* do stuff */
COMMIT


Note that ADODB allowed one to set the default isolation level for the connection, whereas ADO.NET will use the isolation level of the last committed transaction as the default isolation level (see the note in https://msdn.microsoft.com/en-us/library/5ha4240h(v=vs.110).aspx). See https://technet.microsoft.com/en-us/library/ms189542%28v=sql.105%29.aspx?f=255&MSPPError=-2147217396 for details on setting the isolation level for various Microsoft database technologies.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜