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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:14:42+00:00 2026-05-11T12:14:42+00:00

I use NHibernate in my ASP.NET application to connect to an MS SQL Server

  • 0

I use NHibernate in my ASP.NET application to connect to an MS SQL Server 2005 database. In some cases I need to write my own SQL queries. However, I noticed that the SQL server thread leaks about 50 KB of memory every time I execute the following piece of code:

NHibernate.ISession session = NHibernateSessionManager.Instance.GetSession();  ISQLQuery query = session.CreateSQLQuery(   'select {a.*} from t_alarm a where a.deactivationtime > '' +   DateTime.UtcNow.ToString('yyyy-MM-dd HH:mm:ss') +   ''');  query.AddEntity('a', typeof(TAlarm)); System.Collections.IList aList = query.List(); 

When I look in Windows task manager I see that the process sqlservr.exe increases its memory usage by 50 KB each time I run this code.

Here is the really interesting part. If I, in the code above, replace 'yyyy-MM-dd HH:mm:ss' with 'yyyy-MM-dd HH:mm' (i.e. I remove the seconds) the memory leaks stop.

Update: Apparently the memory leaks doesn’t actually stop. They just show once a minute instead. Presumably when the SQL query changes.

The returned results are the same in both cases.

Does anyone have a clue what is going on here?

  • 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. 2026-05-11T12:14:43+00:00Added an answer on May 11, 2026 at 12:14 pm

    a) In the example you are not properly disposing NHibernate’s Session, so the connection to DB is left opened.

    Use using() {} statemenet or try{} cath{} finally{} to properly close connection.

    b) SQL command you have written do not use SQL parameters, so SQL server will see this as a new command every time you execute it – more precisely every second (or if you remove :ss part, then every minute). Use SQL parameters (like NHibernate do when you use HQL, Criteria or QBE quering) and it will be cached properly with less memory consumption.

    Hope this helps;)

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

Sidebar

Ask A Question

Stats

  • Questions 264k
  • Answers 264k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You might want to have a look at ZSync. It's… May 13, 2026 at 12:14 pm
  • Editorial Team
    Editorial Team added an answer Check out argument lists in the Python docs. >>> def… May 13, 2026 at 12:14 pm
  • Editorial Team
    Editorial Team added an answer This should do it, assuming you Epoch date is 1/1/1970… May 13, 2026 at 12:14 pm

Related Questions

I've been working on a .NET application and experiencing a memory error (I'm a
It is very common to create Dependency Injection container for the ASP.NET application so
I'm writing this question from the standpoint of an ASP.NET application. However I realize
I am fairly new to nHibernate and DDD, so please bear with me. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.