Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, In the code below da.Fill(ds) takes around 500ms for the first and drops to 50ms for the second if I call the method without restarting the application. I tried DataReader same thing happens with it. On the other hand I used LINQ to SQL (On MS SQL Server) which returned the records in around 50ms for the first time.

C#
public List<GetEmployeeRightsResult> GetEmployeeRights(System.Nullable<int> p_EmployeeID)
       {
           try
           {


               List<GetEmployeeRightsResult> records = new List<GetEmployeeRightsResult>();

               if (Connection.State != ConnectionState.Open)
               {
                   Connection.Open();
               }

               Command = new MySqlCommand("GetEmployeeRights", Connection);
               Command.CommandType = CommandType.StoredProcedure;

               //Add Parameters is procedures requires.
               Command.Parameters.Add(new MySqlParameter("p_EmployeeID", p_EmployeeID));


               if (Transaction != null)
               {
                   Command.Transaction = Transaction;
               }

               da = new MySqlDataAdapter();
               da.SelectCommand = Command;

               ds = new DataSet();

               Stopwatch sw = new Stopwatch();
               sw.Start();
               da.Fill(ds);
               sw.Stop();
               //Writing Execution Time in label
               string ExecutionTimeTaken = string.Format("Minutes :{0}\nSeconds :{1}\n Mili seconds :{2}", sw.Elapsed.Minutes, sw.Elapsed.Seconds, sw.Elapsed.TotalMilliseconds);



               foreach (DataRow Row in ds.Tables[0].Rows)
               {
                   GetEmployeeRightsResult result = new GetEmployeeRightsResult()
                   {
                       FormID = Convert.ToInt32(Row["FormID"]),
                       FormName = Row["FormName"] == DBNull.Value ? null : (string)Row["FormName"],
                       CanAccess = Convert.ToBoolean(Row["CanAccess"]),
                       Type = Row["Type"] == DBNull.Value ? null : (string)Row["Type"],

                   };

                   records.Add(result);
               }


               return records;
           }
           catch
           {
               throw;
           }
       }


Just 70 lines of record.

SQL
BEGIN

IF(p_EmployeeID = 0)
THEN
	SELECT FormID,FormName,CanAccess,Type from RightsCatalog; 
ELSE
	SELECT
		 ER.StoreID
		,ER.FormID
		,FormName
		,IFNULL(ER.CanAccess,1) as CanAccess
		,RC.Type 
		FROM EmployeeRight ER 
		RIGHT OUTER JOIN RightsCatalog RC 
		ON RC.FormID = ER.FormID  
		WHERE EmployeeID = p_EmployeeID;
END IF;
-- ****** [Objec...  ts ] Script Date: 02/24/2014 10:00:33 *******

END
Posted
Updated 10-Mar-14 3:42am
v2
Comments
thatraja 10-Mar-14 9:06am    
How much records you're loading? millions? Show the storedprocedure content. Update your question
Bernhard Hiller 11-Mar-14 5:45am    
Is MySQL able to cache query results? Well, Microsoft SQL Server does...

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900