Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6579193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:52:03+00:00 2026-05-25T15:52:03+00:00

A third party application creates one database per project. All the databases have the

  • 0

A third party application creates one database per project. All the databases have the same tables and structure. New projects may be added at anytime so I can’t use any EF schema.

What I do now is:

    private IEnumerable<Respondent> getListRespondentWithStatuts(string db)
    {
        return query("select * from " + db + ".dbo.respondent");
    }

    private List<Respondent> query(string sqlQuery)
    {
        using (var sqlConx = new SqlConnection(Settings.Default.ConnectionString))
        {
            sqlConx.Open();
            var cmd = new SqlCommand(sqlQuery, sqlConx);
            return transformReaderIntoRespondentList(cmd.ExecuteReader());
        }
    }

    private List<Respondent> transformReaderIntoRespondentList(SqlDataReader sqlDataReader)
    {
        var listeDesRépondants = new List<Respondent>();

        while (sqlDataReader.Read())
        {
            var respondent = new Respondent
            {
                CodeRépondant = (string)sqlDataReader["ResRespondent"],
                IsActive = (bool?)sqlDataReader["ResActive"],
                CodeRésultat = (string)sqlDataReader["ResCodeResult"],
                Téléphone = (string)sqlDataReader["Resphone"],
                IsUnContactFinal = (bool?)sqlDataReader["ResCompleted"]
            };

            listeDesRépondants.Add(respondent);
        }

        return listeDesRépondants;
    }

This works fine, but it is deadly slow (20 000 records per minutes). Do you have any hints on what strategy should be faster? For info, what is really slow is transformReaderIntoRespondentList method

Thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:52:05+00:00Added an answer on May 25, 2026 at 3:52 pm

    Generally speaking anything SELECT * FROM is bad practice, but it could also be resulting in you having to pull back more data than is actually required. The transform is operating on only a few columns are more columns than required being returned? Consider replacing with:

      private IEnumerable<Respondent> getListRespondentWithStatuts(string db)
      {
        return query("select ResRespondent, ResActive, ResCodeResult, Resphone, ResCompleted  from " + db + ".dbo.respondent");
      }
    

    Also, gaurd against SQL-Injection attacks; concating strings for SQL queries is very dangerous.

    When pulling data from a DataReader, I find that using the non-named lookups work best:

      var respondent = new Respondent
      {
        CodeRépondant = sqlDataReader.GetString(0),
        IsActive = sqlDataReader.IsDBNull(1) ? (Boolean?)null : sqlDataReader.GetBoolean(1),
        CodeRésultat = sqlDataReader.GetString(2),
        Téléphone = sqlDataReader.GetString(3),
        IsUnContactFinal = sqlDataReader.IsDBNull(4) ? (Boolean?)null : sqlDataReader.GetBoolean(4)
      };
    

    I have not explcicitly tested the performance difference in a long while; but that used to make a notable difference. The ordinal checks did not have to do a named lookup and also avoided boxing/unboxing values.

    Other than that, without more info it is hard to say… do you need all 20,000 records?

    UPDATE

    Ran a simple local test case with 300,000 records and reduced the time to load all data by almost 50%. I imagine these results will vary depending on the type of data being retrieved; but it still does make a difference on overall execution time. That being said, in my environment we are talking a drop from 650ms to just over 300ms.

    NOTE

    If respondent is a view, what is likely “really slow” is the database building up the result set; although the data reader will start processing information as soon as records are available, the ultimate bottleneck will be the database itself and/or network latency. Other than the above optimizations, there is not going to be much that you can do with your code unless you can index the view/table to optimize the query and or reduce the information required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a third party Application that does background work, but prints out
I am using a third party application and would like to change one of
I have a third party .NET Assembly and a large Java application. I need
We have a third party application that provied its web services to us by
Is it preferred to create tables in mysql using a third party application (phpmyadmin,
I am using a third-party application, and making a call to create an instance
My ClickOnce application uses a third party tool that requires the Visual C++ 2005
My application depends on another third-party framework and I need to make sure the
I'm consuming a third party .NET WebService in my client application. For debugging purposes
My application has a plug-in model that allows third-party developers to write assemblies that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.