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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:05:05+00:00 2026-06-15T10:05:05+00:00

How does Dapper help protect against SQL injections? I am testing out different DAL

  • 0

How does Dapper help protect against SQL injections? I am testing out different DAL technologies and have to choose one to be secure our site. I’m leaning towards Dapper (http://code.google.com/p/dapper-dot-net/), but need some help learning about security.

  • 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-15T10:05:06+00:00Added an answer on June 15, 2026 at 10:05 am

    How does Dapper help protect against SQL injections?

    It makes it really, really easy to do fully parameterized data access, without ever needing to either concatenate input. In particular, because you don’t need to jump through lots of “add parameter, set the parameter type, check for null because ADO.NET has sucky null-handling, rinse/repeat for 20 parameters”, by making parameter handling stupidly convenient. It also makes turning rows into objects really easy, avoiding the temptation to use DataTable… everyone wins.

    From comments:

    One more…what does dapper actually help do then?

    To answer, let’s take the example from marc_s’s reply, and write it the old way, assuming all we have to start with is connection. This is then:

    List<Dog> dogs = new List<Dog>();
    using(var cmd = connection.CreateCommand()) {
        cmd.CommandText = "select Age = @Age, Id = @Id";
        cmd.Parameters.AddWithValue("Age", DBNull.Value);
        cmd.Parameters.AddWithValue("Id", guid);
        using(var reader = cmd.ExecuteReader()) {
            while(reader.Read()) {
                int age = reader.ReadInt32("Age");
                int id = reader.ReadInt32("Id");
                dogs.Add(new Dog { Age = age, Id = id });
            }
            while(reader.NextResult()) {}
        }
    }
    

    except I’ve over-simplfied grossly, as it also deals with a wide range of issues such as:

    • null handling of parameters
    • null handling of result columns
    • using the ordinal column indices
    • adapting to structural changes of the underlying table and type
    • data conversion of result columns (between various primitives, strings, enums, etc)
    • special handling of the oh-so-common “in this list” scenario
    • for “execute”, special handling of the “apply this separately to a list of inputs”
    • avoiding silly typos
    • reducing code maintenance
    • handling multiple grids
    • handling multiple objects returned horizontally in a single grid
    • working with arbitrary ADO.NET providers (hint: AddWithValue rarely exists)
      • including specific support for things like Oracle, which needs additional configuration
      • plays nicely with ADO.NET decoratos such as “mini-profiler”
    • inbuilt support for both buffered (suitable for small-to-moderate data; minimises command duration) and non-bufferesd (suitable for large data; minimised memory usage) accesss
    • optimized by people who care about performance and know “quite a bit” about both data-access and meta-programming
    • allows you to use your choice of POCO / DTO / anon-type / whatever for both the parameter and output
    • allows use of either dynamic (for multi-column) or primitives etc (for single column) when the output doesn’t warrant generation a POCO / DTO
    • avoid the overhead of complex fully-typed ORMs like EF
    • avoid the overhead of weak-typed layers like DataTable
    • opening and closing connections as-necessary
    • and a vast range of other common gotchas
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does any one have a solution to make the SpecFlow autocomplete in Visual Studio
Does anyone have any experience with PHP QuickHash ( http://php.net/manual/en/book.quickhash.php )? Some early testing
Does anyone know if there is a way to generate different code in the
Does COUNT(*) have any significant impact for MySQL performance if query already has GROUP
Does anyone have a translate function for x/y positions after rotation in javascript? for
Does anyone know why UsernameExists wont return True. I must have my syntax messed
Does anyone out there know how to integrate ContentFlow ( http://www.jacksasylum.eu/ContentFlow ) and Lightbox2
Does anyone know of a mechanism in Sybase ASA 9 / Sybase SQL Anywhere
Does anyone out there know what image format results in the fastest loading speeds?
Does anyone have any suggestions for the best / simplest way to view all

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.