Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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:

C#
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;
Posted
Updated 9-Apr-13 3:56am
v2
Comments
SriNivas IT 9-Apr-13 9:48am    
what is the problem in datareader or any other????

Please help me???
ZurdoDev 9-Apr-13 10:22am    
How many records are there? It may be that there are too many and you are dumping them into a List of some custom class and you're probably using too much memory.

1 solution

You are fetching the data from SQL server and again filtering it in the C# side. Why not move this hardcoded condition to stored procedure itself in the WHERE clause ??

SQL
WHERE ServiceLevel <> 'L2' AND ServiceRequestStatus <> 'Repaired'


This will decrease a lot of overhead if there are a large number of records that are to be filtered. You must be aware of how much records you are actually fetching before applying the condition above and how many do you really need.

Imagine you fetch 1 million records and you need only 100..

Records with this condition are fetched but not used.... Then why fetch

C#
if ((Convert.ToString(reader["ServiceLevel"]) == "L2") && (Convert.ToString(reader["ServiceRequestStatus"]) == "Repaired"))
                        continue;
 
Share this answer
 
v2
Comments
SriNivas IT 11-Apr-13 5:59am    
ok! but the problem is that there is lot of time in fetch first record also (of many rows).
but in back end it takes 10 seconds and using datareader it takes more that 10 minuts even for first record .
bbirajdar 11-Apr-13 11:58am    
I agree .. Its normal..if you want to dig deep, then check how objects are created , the memory allocated and time consumes using .net profiling tools
http://msdn.microsoft.com/en-in/library/dd255392.aspx
http://msdn.microsoft.com/en-us/magazine/hh288073.aspx
http://msdn.microsoft.com/en-us/magazine/cc337887.aspx

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