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

  • SEARCH
  • Home
  • 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 6565875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:08:56+00:00 2026-05-25T14:08:56+00:00

I have a SQL query that takes less than a second to execute when

  • 0

I have a SQL query that takes less than a second to execute when I’m using SQL Management Studio, but when my code executes it, it takes over 30 seconds to get the result from the database server. The result contains 1700 rows. Another similar query, that returns 900 rows, takes a few ms to execute. What can be the reason for this odd behaviour?

    public SqlDataReader ExecuteReader(string strSQL, ArrayList arParams)
    {
        OpenConnection();

        SqlCommand myCommand = new SqlCommand(strSQL, myConnection);
        myCommand.CommandTimeout = intTimeout;


        foreach (SqlParameter myParameter in arParams)
            myCommand.Parameters.Add(myParameter);

        return myCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
    }

strSQL:

SELECT [Group].[Id]
       ,[Group].[intCustomerId]   
       ,[Group].[strName]
       ,[Permission].[dtmCreated]
       ,[Permission].[intPermissionTypeId]
       ,[Permission].[intObjectTypeId]          
       ,[Permission].[intObjectId]            
       ,[Permission].[blnActive]            
       ,[Permission].[blnHaveAccess]
       ,[Permission].[intLevelTypeId]             
 FROM [Group]
 LEFT JOIN Permission ON [Group].[Id] = intGroupId AND 
                         intObjectId = @ObjectId AND 
                         intObjectTypeId = @ObjectTypeId AND 
                         intLevelTypeId = @LevelType AND
                         intPermissionTypeId = @PermissionTypeId AND
                         blnActive = 1                                             
 WHERE [Group].[intCustomerId] = @CustomerId  AND
       [Group].[blnDeleted] = 0
 ORDER BY strName, blnActive DESC

arParams:

arParams.Add(DatabaseHandler.MakeSqlParameter("@CustomerId", customer.Id));
arParams.Add(DatabaseHandler.MakeSqlParameter("@ObjectId", masterprocess.Id));
arParams.Add(DatabaseHandler.MakeSqlParameter("@ObjectTypeId", Convert.ToInt32(ObjectType.MasterProcess)));
arParams.Add(DatabaseHandler.MakeSqlParameter("@PermissionTypeId", Convert.ToInt32(permissiontype)));
arParams.Add(DatabaseHandler.MakeSqlParameter("@LevelType", Convert.ToInt32(leveltype)));

DatabaseHandler.MakeSqlParameter:

public static SqlParameter MakeSqlParameter(String strName, int intInput)
{
    return new SqlParameter(strName, intInput);
}
  • 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-25T14:08:57+00:00Added an answer on May 25, 2026 at 2:08 pm

    Based on your reply on comments i would say the correct solution is indexes.

    Simplest way would be to run the sql logging for a bit when you run the normal queries, and then afterward run the run the sql profiler.

    Based on its recommendations it could have spottet a missing indexes.

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

Sidebar

Related Questions

I have an SQL query that takes the following form: UPDATE foo SET flag=true
I have a SQL query that takes a very long time to run on
I have a sql query that runs super fast, around one second, when not
I have a query that takes 5 seconds to run in SQL Server Managment
We have a SQL query that pulls a large number of fields from many
I have a SQL query that is supposed to pull out a record and
I have a Linq to SQL query that was working just fine with SQL
I have a result from an SQL query that I would like to sort
I have a query that runs super fast when executed in the sql editor
I have a query that I'm executing from a .NET application to a SQL

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.