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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:38:55+00:00 2026-06-12T01:38:55+00:00

Dapper implicitly expects a connection to be open when it uses it. Why doesn’t

  • 0

Dapper implicitly expects a connection to be open when it uses it. Why doesn’t it open and close it itself? Wouldn’t this simply connection management?

I ask because a co-worker and I have been going back and forth on the nature of what goes on behind the scenes with connection pooling, and if there is any benefit to keeping a connection open amongst multiple commands, or to open and close it for each command.

  • 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-06-12T01:38:56+00:00Added an answer on June 12, 2026 at 1:38 am

    Dapper now (and for quite some time) deals with this internally. It just works™


    Original (outdated) answer:

    You aren’t wrong. The reason I hadn’t noticed this inconvenience is that for legacy reasons (specifically: we used to use LINQ-to-SQL exclusively) our primary connection-like-thing is a DataContext – so we re-expose the dapper methods as extension methods on DataContext.

    The silly thing is: what these methods do is:

    using(db.Connection.EnsureOpen()) {
        db.Connection.{the dapper method}
    }
    

    Here EnsureOpen is a cheeky method that:

    • if the connection is open, returns null
    • otherwise, it opens the connection, and returns an IDisposable token that closes the connection when done

    So: we obviously felt exactly your pain, but we implemented it a layer further up.

    Please log this as a feature request. We have all the code (although I’ll need to tweak it slightly to fit the “reader” for non-buffered data) – there’s absolutely no reason that dapper can’t take ownership of this.

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

Sidebar

Related Questions

I'm just reading this sample from the Dapper manual: connection.Execute(@ set nocount on create
I'm using the Dapper micro ORM. I thought it could handle enumerables like this:
Here on this page, Scott Hanselman shows two examples from Micro-ORMs Dapper and Massive,
(This code is using Dapper Dot Net in C#) This code works: var command
Is this query safe against sql injection in combination with Dapper? If not, what
Where can I find more information on connection pooling with Dapper.net?
I'm referring to this SO question: Bulk inserts taking longer than expected using Dapper
I'm trying to use Dapper simply to map my database tables to types in
I am wanting to use the MVCMiniProfiler with Dapper. Is this possible beyond wrapping
Is this the least amount of code I can use to convert a Dapper

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.