Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL script takes long time to run

I'm currently using Microsoft Enterprise Library Data Access 5.0 to execute a stored procedure.

Database myDatabase = DatabaseFactory.CreateDatabase();
using (DbCommand command = myDatabase.GetStoredProcCommand("myStoredProc"))
{
   //Add parameters here
   using (IDataReader dataReader = myDatabase.ExecuteReader(command))
   {
      while (dataReader.Read())
      {
      }
   }
}

Everything works however it takes a long time to run. When I turn on SQL Profiler, I can see the stored procedure takes about 50 seconds to run. However, if i take that same scripts from the Profiler and run it inside SQL Management Studio, it only takes about 480 miliseconds to return all the rows.

Has anyone run into this issue? Why is there a big difference?

like image 309
madatanic Avatar asked Nov 13 '22 10:11

madatanic


1 Answers

Could easily be Parameter Sniffing.

like image 50
Phil Sandler Avatar answered Nov 14 '22 22:11

Phil Sandler