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 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

Related Questions

I use ASP.Net with NHibernate accessing a Pgsql database. For some of our Objects,
I'm developing an ASP.NET MVC application with NHibernate and I'm trying to use Automapper
I'm checking out Linq for NHibernate 2.1 to use in an ASP.NET MVC application
I have just re-implemented an ASP.NET web application that uses NHibernate to use a
In my ASP.NET web-application I use NHibernate to persist my User-Instances, where each of
I rewrite application from ASP.NET to Silverlight and use NHibernate 2. Tables in my
I'm a little confused. We have developed an net 4.0 application. We use nhibernate
I'm creating a multi-tenant ASP.NET application using NHibernate (shared schema). I had intended to
I'm using Spring.NET 1.3.2, NHibernate 3.1 and the OSIV pattern in a ASP.NET application.
I have a C# WinForms application with a database backend (oracle) and use NHibernate

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.