Can I force SQL SMO to use READ UNCOMMITTED isolation?

谁说胖子不能爱 提交于 2019-12-11 03:02:34

问题


I have an application which is using SQL2008 SMO to grab the SpaceAvailable property of all of the databases, but it often becomes blocked by other processes for long a duration. I have noted that I can run the query it generates in SSMS with no issues in READ UNCOMMITTED isolation.

So, do a way exist to force SQL SMO to use read uncommitted isolation?


回答1:


Sorry for the late reply to this. Figured I'd post this in in case someone needs help in the future.

You can set specify the isolation level when you create your Server instance.

Make sure you have the following references:

using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.ConnectionInfo; 

And then set the isolation level when creating the connection

Server theSQLServer = new Server(@"cb-z420vmsasq1\sql12");
        theSQLServer.ConnectionContext.SqlConnectionObject.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);

You may have to change this for different transactions.




回答2:


Yes You can use SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED at the top of your query. Also you can change isolation level to your need. Search msdn.microsoft.com for isolation levels.



来源:https://stackoverflow.com/questions/19041738/can-i-force-sql-smo-to-use-read-uncommitted-isolation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!