This is a migrated thread and some comments may be shown as answers.

It is a lot of requests when the connected parameters load

2 Answers 32 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
ADM-IT Denis Pujdak
Top achievements
Rank 1
ADM-IT Denis Pujdak asked on 24 Apr 2012, 08:42 PM
I couldn't check that switching of parameter will create 1016 requests. Now of it it was convinced. I asked myself a question: why loading of lists occurs so long. Why the sqlDataSourceAddresses requests data so many time?
For my case only once suffices, because parameters:
@adrType, @proTypeOwner, @proConId, @proDepId, @proDate, @userId
 don't change.

Thanks.

2 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 27 Apr 2012, 11:35 AM
Hi Denis,

We're not sure we understand your inquiry. If your data source parameters do not change, then do not create corresponding report parameters and the report would not query the data source for parameter values. If you hardcode the values of the data source parameters, the query would be executed only once and the SqlDataSource component would cache the data for subsequent requests like exporting or printing.

All the best,
Steve
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

0
ADM-IT Denis Pujdak
Top achievements
Rank 1
answered on 27 Apr 2012, 02:03 PM
Thanks for information. I found the response by means of other method (objectDataSource):

public class AdrAddressesCache
{
    public string adrElement { get; set; }
    public string parameters { get; set; }
    public List<AddressElement> CachedList { get; set; }
}
 
public class AdrAddresses
{
    private static List<AdrAddressesCache> CacheAddresses = new List<AdrAddressesCache>();
    private static int counter = 0;
 
    public List<AddressElement> GetAdrAddresses(string adrType, string adrElement, string adrCountry, string adrRegion, string adrPlace, string adrCommunity, string adrCity, string adrStreet, Nullable<int> proTypeOwner, Nullable<int> proConId, Nullable<int> proDepId, Nullable<DateTime> proDate, Nullable<int> userId)
    {
        string element = adrType + adrElement;
        string parameters = adrCountry + adrRegion + adrPlace + adrCommunity + adrCity + adrStreet + proTypeOwner.ToString() + proConId.ToString() + proDepId.ToString() + proDate.ToString() + userId.ToString();
        if (CacheAddresses.Where(x => x.adrElement == element).Count() > 0)
        {
            if (CacheAddresses.Where(x => x.adrElement == element && x.parameters == parameters).Count() > 0)
            {
                return CacheAddresses.Where(x => x.adrElement == element && x.parameters == parameters).FirstOrDefault().CachedList;
            }
        }
        else
        {
            CacheAddresses.Add(new AdrAddressesCache() { adrElement = element });
        }
        using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionMainDataBase"].ConnectionString))
        {
            counter++;
            Debug.WriteLine("EXECUTE Addresses: " + adrElement + "[" + counter + "]");
            SqlCommand cmd = new SqlCommand("Custom.adrAddress_GetAddressesElementByUse", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            if (!String.IsNullOrEmpty(adrType)) cmd.Parameters.Add("@adrType", SqlDbType.NVarChar).Value = adrType;
            cmd.Parameters.Add("@adrElement", SqlDbType.NVarChar).Value = adrElement;
            if (!String.IsNullOrWhiteSpace(adrCountry)) cmd.Parameters.Add("@adrCountry", SqlDbType.NVarChar).Value = adrCountry;
            if (!String.IsNullOrWhiteSpace(adrRegion)) cmd.Parameters.Add("@adrRegion", SqlDbType.NVarChar).Value = adrRegion;
            if (!String.IsNullOrWhiteSpace(adrPlace)) cmd.Parameters.Add("@adrPlace", SqlDbType.NVarChar).Value = adrPlace;
            if (!String.IsNullOrWhiteSpace(adrCommunity)) cmd.Parameters.Add("@adrCommunity", SqlDbType.NVarChar).Value = adrCommunity;
            if (!String.IsNullOrWhiteSpace(adrCity)) cmd.Parameters.Add("@adrCity", SqlDbType.NVarChar).Value = adrCity;
            if (!String.IsNullOrWhiteSpace(adrStreet)) cmd.Parameters.Add("@adrStreet", SqlDbType.NVarChar).Value = adrStreet;
            if (proTypeOwner.HasValue && proTypeOwner.Value > 0) cmd.Parameters.Add("@proTypeOwner", SqlDbType.Int).Value = proTypeOwner.Value;
            if (proConId.HasValue && proConId.Value > 0) cmd.Parameters.Add("@proConId", SqlDbType.Int).Value = proConId.Value;
            if (proDepId.HasValue && proDepId.Value > 0) cmd.Parameters.Add("@proDepId", SqlDbType.Int).Value = proDepId.Value;
            if (proDate.HasValue && proDate.Value > DateTime.MinValue) cmd.Parameters.Add("@proDate", SqlDbType.Date).Value = proDate.Value.Date;
            if (userId.HasValue && userId.Value > 0) cmd.Parameters.Add("@userId", SqlDbType.Int).Value = userId.Value;
 
            cn.Open();
            IDataReader reader = cmd.ExecuteReader(CommandBehavior.Default);
            List<AddressElement> AddressElements = new List<AddressElement>();
            while (reader.Read())
            {
                if (reader.FieldCount > 0)
                {
                    AddressElement adr = new AddressElement()
                    {
                        adrElement = reader["adrElement"].ToString()
                    };
                    AddressElements.Add(adr);
                }
            }
            CacheAddresses.Where(x => x.adrElement == element).FirstOrDefault().parameters = parameters;
            CacheAddresses.Where(x => x.adrElement == element).FirstOrDefault().CachedList = AddressElements;
            return AddressElements;
        }
    }
}

In the attachmented file you will see result.

Thanks for Telerik.Reporting & Telerik.Silverlight
Tags
General Discussions
Asked by
ADM-IT Denis Pujdak
Top achievements
Rank 1
Answers by
Steve
Telerik team
ADM-IT Denis Pujdak
Top achievements
Rank 1
Share this question
or