问题
I am executing a simple query against SQL Server 2005:
protected static void InitConnection(IDbCommand cmd) {
cmd.CommandText = "set transaction isolation level read uncommitted ";
cmd.ExecuteNonQuery();
}
Whenever I profile with dotTrace 3.1, it claims that SNIReadSync method is taking between 100 - 500 ms.
What sort of things do I need to be looking for in order to get this time down?
Thanks!
回答1:
I have not tested, but would wonder if you have the same issue if you used a TransactionScope with the options of IsolationLevel.ReadUncommitted. You would have to encapsulate your complete set of calls and that should negate the need for this statement. I realize that this statement is not your basic concern, but in general.
Another thing that you can do is to create a DBConnectionScope class (or leverage a trusted vendor's class) and cut down on the total number of connections that are opened.
回答2:
Ensure that connection pooling is enabled or you will receive a significant penalty each time a connection is opened. In your connection string set Pooling=True, or remove any reference to pooling. I believe the default is enabled.
This fixed the issue for me. Hope it helps for you and others.
来源:https://stackoverflow.com/questions/1610874/snireadsync-executing-between-120-500-ms-for-a-simple-query-what-do-i-look-for