My profiler trace shows that exec sp_reset_connection
is being called between every sql batch or procedure call. There are reasons for it, but can I prevent it from
This Q/A could be helpful: What does "exec sp_reset_connection" mean in Sql Server Profiler?
However, I did a quick test using Entity Framework and MS-SQL 2008 R2. It shows that "exec sp_reset_connection" isn't time consuming after the first call:
for (int i = 0; i < n; i++)
{
using (ObjectContext context = new myEF())
{
DateTime timeStartOpenConnection = DateTime.Now;
context.Connection.Open();
Console.WriteLine();
Console.WriteLine("Opening connection time waste: {0} ticks.", (DateTime.Now - timeStartOpenConnection).Ticks);
ObjectSet query = context.CreateObjectSet();
DateTime timeStart = DateTime.Now;
myEntity e = query.OrderByDescending(x => x.EventDate).Skip(i).Take(1).SingleOrDefault();
Console.Write("{0}. Created By {1} on {2}... ", e.ID, e.CreatedBy, e.EventDate);
Console.WriteLine("({0} ticks).", (DateTime.Now - timeStart).Ticks);
DateTime timeStartCloseConnection = DateTime.Now;
context.Connection.Close();
context.Connection.Dispose();
Console.WriteLine("Closing connection time waste: {0} ticks.", (DateTime.Now - timeStartCloseConnection).Ticks);
Console.WriteLine();
}
}
And output was this:
Opening connection time waste: 5390101 ticks. 585. Created By sa on 12/20/2011 2:18:23 PM... (2560183 ticks). Closing connection time waste: 0 ticks.
Opening connection time waste: 0 ticks. 584. Created By sa on 12/20/2011 2:18:20 PM... (1730173 ticks). Closing connection time waste: 0 ticks.
Opening connection time waste: 0 ticks. 583. Created By sa on 12/20/2011 2:18:17 PM... (710071 ticks). Closing connection time waste: 0 ticks.
Opening connection time waste: 0 ticks. 582. Created By sa on 12/20/2011 2:18:14 PM... (720072 ticks). Closing connection time waste: 0 ticks.
Opening connection time waste: 0 ticks. 581. Created By sa on 12/20/2011 2:18:09 PM... (740074 ticks). Closing connection time waste: 0 ticks.
So, the final conclusion is: Don't worry about "exec sp_reset_connection"! It wastes nothing.