为什么MySQLDataAdapter.Fill()第一次需要这么长时间。 [英] Why does MySQLDataAdapter.Fill() takes so long for the first time.
本文介绍了为什么MySQLDataAdapter.Fill()第一次需要这么长时间。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的代码中,如果我在不重新启动应用程序的情况下调用方法,da.Fill(ds)第一次占用大约500ms,第二次占用50ms。我试过DataReader同样的事情发生了。另一方面,我使用LINQ to SQL(在MS SQL Server上),这是第一次在大约50ms内返回记录。
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;
//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;
}
}
只有70行记录。
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;
-- ****** [Objec... ts ] Script Date: 02/24/2014 10:00:33 *******
END
推荐答案
这可能是任何事情。 IDE错误,操作系统问题,即虚拟机或SSMS设置。
请参阅:
http://stackoverflow.com/questions/7992560/sqldataadapter-fill-suddenly-taking-a-long-time [ ^ ]
http://stackoverflow.com/questions/250713/sqldataadapter-fill-method-slow [ ^ ]
-KR
This could be anything. IDE bug, OS problem i.e Virtual Machine or settings of SSMS.
See this :
http://stackoverflow.com/questions/7992560/sqldataadapter-fill-suddenly-taking-a-long-time[^]
http://stackoverflow.com/questions/250713/sqldataadapter-fill-method-slow[^]
-KR
这篇关于为什么MySQLDataAdapter.Fill()第一次需要这么长时间。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文