本文介绍了请解决问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,

有一个程序我用来从后端Sql服务器获取数据



需要10秒钟(几乎)在后端(在Management Studio 2008中运行)



但是在结束时它需要花费太多时间(差不多20分钟)和相同的搜索条件。



我的代码如下:



 IDataReader reader = ; 
列表< pendingcall> listPendingCallReport = new List< pendingcall>();
try
{
connForPedningCallReport = new SqlConnection(ConfigurationManager.AppSettings [ PendingCallReportConn]。ToString());

cmdPendingCallReport = new SqlCommand();

cmdPendingCallReport.Connection = connForPedningCallReport;
cmdPendingCallReport.CommandType = CommandType.StoredProcedure;
cmdPendingCallReport.CommandText = Constants.USP_FETCHPENDINGCALLREPORT.ToString();
cmdPendingCallReport.CommandTimeout = Convert.ToInt32(ConfigurationManager.AppSettings [ CommandTimeout]);
if (pendingCall.IMEINumber ==
pendingCall.IMEINumber = null ;
if (pendingCall.ServiceRequestNumber ==
pendingCall.ServiceRequestNumber = null ;

cmdPendingCallReport.Parameters.AddWithValue( @ ZoneId,pendingCall.ZoneId );
cmdPendingCallReport.Parameters.AddWithValue( @ StateId,pendingCall.StateId);
cmdPendingCallReport.Parameters.AddWithValue( @ CityId,pendingCall.CityId);
cmdPendingCallReport.Parameters.AddWithValue( @ AspId,pendingCall.AspId);
cmdPendingCallReport.Parameters.AddWithValue( @ FromDate,pendingCall.FromDate);
cmdPendingCallReport.Parameters.AddWithValue( @ ToDate,pendingCall.ToDate);
cmdPendingCallReport.Parameters.AddWithValue( @ SRNumber,pendingCall.ServiceRequestNumber);
cmdPendingCallReport.Parameters.AddWithValue( @ IMEINumber,pendingCall.IMEINumber);
cmdPendingCallReport.Parameters.AddWithValue( @ BrandId,pendingCall.BrandId);
cmdPendingCallReport.Parameters.AddWithValue( @ ModelId,pendingCall.ModelId);
cmdPendingCallReport.Parameters.AddWithValue( @ UserId,HttpContext.Current.Session [EnumSession] .UserID.ToString()]);

if (connForPedningCallReport.State!= ConnectionState.Open)
connForPedningCallReport.Open();

reader = cmdPendingCallReport.ExecuteReader(CommandBehavior.CloseConnection);
while (reader.Read())
{
if ((Convert.ToString(reader [ ServiceLevel])== L2)&&(Convert.ToString(reader [ ServiceRequestStatus])== 已修复))
继续;
listPendingCallReport.Add(ReadPendingCallReport(reader));
}
return listPendingCallReport;
解决方案

Hi Friends,
There is a Procedure i used to Fetch data from Back-End Sql server

it takes 10 seconds(almost) in back end (run in Management Studio 2008)

but at frond end it takes too much time (almost 20 minuts) with same search criteria.

My Code is as:

IDataReader reader = null;
            List<pendingcall> listPendingCallReport = new List<pendingcall>();
            try
            {
                connForPedningCallReport = new SqlConnection(ConfigurationManager.AppSettings["PendingCallReportConn"].ToString());

                cmdPendingCallReport = new SqlCommand();

                cmdPendingCallReport.Connection = connForPedningCallReport;
                cmdPendingCallReport.CommandType = CommandType.StoredProcedure;
                cmdPendingCallReport.CommandText = Constants.USP_FETCHPENDINGCALLREPORT.ToString();
                cmdPendingCallReport.CommandTimeout= Convert.ToInt32(ConfigurationManager.AppSettings["CommandTimeout"]);
                if (pendingCall.IMEINumber == "")
                    pendingCall.IMEINumber = null;
                if (pendingCall.ServiceRequestNumber == "")
                    pendingCall.ServiceRequestNumber = null;

                cmdPendingCallReport.Parameters.AddWithValue("@ZoneId", pendingCall.ZoneId);
                cmdPendingCallReport.Parameters.AddWithValue("@StateId", pendingCall.StateId);
                cmdPendingCallReport.Parameters.AddWithValue("@CityId", pendingCall.CityId);
                cmdPendingCallReport.Parameters.AddWithValue("@AspId", pendingCall.AspId);
                cmdPendingCallReport.Parameters.AddWithValue("@FromDate", pendingCall.FromDate);
                cmdPendingCallReport.Parameters.AddWithValue("@ToDate", pendingCall.ToDate);
                cmdPendingCallReport.Parameters.AddWithValue("@SRNumber", pendingCall.ServiceRequestNumber);
                cmdPendingCallReport.Parameters.AddWithValue("@IMEINumber", pendingCall.IMEINumber);
                cmdPendingCallReport.Parameters.AddWithValue("@BrandId", pendingCall.BrandId);
                cmdPendingCallReport.Parameters.AddWithValue("@ModelId", pendingCall.ModelId);
                cmdPendingCallReport.Parameters.AddWithValue("@UserId",  HttpContext.Current.Session[EnumSession.UserID.ToString()]);

                if (connForPedningCallReport.State != ConnectionState.Open)
                    connForPedningCallReport.Open();

                reader = cmdPendingCallReport.ExecuteReader(CommandBehavior.CloseConnection);
                while (reader.Read())
                {
                    if ((Convert.ToString(reader["ServiceLevel"]) == "L2") && (Convert.ToString(reader["ServiceRequestStatus"]) == "Repaired"))
                        continue;
                    listPendingCallReport.Add(ReadPendingCallReport(reader));
                }
                return listPendingCallReport;
解决方案


这篇关于请解决问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 00:03