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.
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;
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();
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.
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;
END