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 1060949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:24:16+00:00 2026-05-16T18:24:16+00:00

I am having some issues when running sp_executesql on a database table. I am

  • 0

I am having some issues when running sp_executesql on a database table. I am using an ORM (NHibernate) that generates a SQL query that queries one table in this case. This table has about 7 million records in it and is highly indexed.

When I run the query that the ORM spits out without the sp_executesql, it runs very quickly and profiler shows it has 85 reads. When I run the same query using sp_executesql, it has around 201,828 reads.

Is there something I need to do on my SQL Server to improve the performance of running the query without sp_exectuesql? It seems as though its not using my Indexes.

What is the best way to fix this issue? If possible, I would rather not change the way the ORM is generating the SQL but instead fix the problem at the SQL Server/database level because it seems that is where the problem is. I’m guessing I need to do more optimization on the database to fix this problem I just don’t know what.

exec sp_executesql N'SELECT top 20 
                            this_.Id as Id0_0_, 
                            this_.Application as Applicat2_0_0_, 
                            this_.[Context] as column3_0_0_, 
                            this_.Logger as Logger0_0_, 
                            this_.Message as Message0_0_, 
                            this_.Exception as Exception0_0_, 
                            this_.Thread as Thread0_0_, 
                            this_.[Level] as column8_0_0_, 
                            this_.LogDate as LogDate0_0_, 
                            this_.SessionId as SessionId0_0_ 
                       FROM LogMessages this_ 
                      WHERE this_.[Context] = @p0',
                   N'@p0 nvarchar(2)',
                   @p0 = N'55'

Context is a varchar(255). This field is very free form. It isn’t always an integer and the length may very. In this case, I am querying for a value of ’55’ but it could just as easily be querying for ‘Foooooobaaaarrr’

  • 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-16T18:24:17+00:00Added an answer on May 16, 2026 at 6:24 pm

    what is the data type of .[Context] use the same datatype

    right now you are using nvarchar(2) but that seems odd for something like 55, if you are not using the same data types you will get conversions which then cause scans

    based on your updated question, it looks like it is varchar(255), then do this

    WHERE this_.[Context] = @p0',N'@p0 varchar(255)',@p0='55'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some issues implementing JPA 2.0 in my app. I'm using Criteria queries
I'm having some issues with using PHP to convert ISO-8859-1 database content to UTF-8.
I'm running into some issues with having a lot of UIImages in memory, so
I'm having some issues to deserialize a Json array that follows this format: [
I am having some issues with a code that is occasionally and sporadically throwing
Recently I was having some issues with a singelton class that was lazy initializing
I'm having some issues deploying a Visio addin. Running the VSTO file works on
I'm having some performance issues calling CGContextDrawLayerAtPoint in iOS 4 that didn't seem to
Having some issues running my code local. I have host file setup like this:
I'm having some build issues with Eclipse in that it runs my app just

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.