Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. C# CommandType.Text and CommandType.StoredProcedure

C# CommandType.Text and CommandType.StoredProcedure

Scheduled Pinned Locked Moved C#
databasecsharpsql-serversysadminperformance
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Christopher Stratmann
    wrote on last edited by
    #1

    I have a SQL Server 2000 database which my C# application is storing data into. I would like to know if there is any real benefit using stored procedures from my C# code than using straight SQL text. I know there is probably a lot of benefit using a stored procedure if what I want to accomplish is very complicated. So here is my questions.... Is there any real performance gain to use a stored procedure if my SQL text is a simple 'select', 'update', 'insert', or 'delete' statement(meaning the SQL text only involves one table and is very basic)? Is there any real performance gain to use a stored procedure if my SQL text is a 'select' statement that has around 3 'inner joins'? Thanks Chris

    T N 2 Replies Last reply
    0
    • C Christopher Stratmann

      I have a SQL Server 2000 database which my C# application is storing data into. I would like to know if there is any real benefit using stored procedures from my C# code than using straight SQL text. I know there is probably a lot of benefit using a stored procedure if what I want to accomplish is very complicated. So here is my questions.... Is there any real performance gain to use a stored procedure if my SQL text is a simple 'select', 'update', 'insert', or 'delete' statement(meaning the SQL text only involves one table and is very basic)? Is there any real performance gain to use a stored procedure if my SQL text is a 'select' statement that has around 3 'inner joins'? Thanks Chris

      T Offline
      T Offline
      TJoe
      wrote on last edited by
      #2

      There are two things to consider: performance and flexibility. For performance, you may see a slight improvement with SPs because SQL Server can "compile" them ahead of time. When performing ad-hoc queries, SQL Server must "compile" them every time (with some exceptions). If you are running simple selects then you probably would never notice an improvement. When doing simply selects, your main benefit comes from flexibility. SPs allow you to quickly and easily change the underlying T-SQL code (whether it's a simple select or something more complex) *without* having to re-compile your .Net code. It is possible to "store" the T-SQL code in a config file. This would still allow you to change your code without recompiling your binaries, but SPs are generally the preferred method.

      Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

      1 Reply Last reply
      0
      • C Christopher Stratmann

        I have a SQL Server 2000 database which my C# application is storing data into. I would like to know if there is any real benefit using stored procedures from my C# code than using straight SQL text. I know there is probably a lot of benefit using a stored procedure if what I want to accomplish is very complicated. So here is my questions.... Is there any real performance gain to use a stored procedure if my SQL text is a simple 'select', 'update', 'insert', or 'delete' statement(meaning the SQL text only involves one table and is very basic)? Is there any real performance gain to use a stored procedure if my SQL text is a 'select' statement that has around 3 'inner joins'? Thanks Chris

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        In addition to what has already been stated, security is another reason to use stored procs over in-line SQL. Unless you have strong, bullet-proof validation, using in-line SQL opens your app to SQL injection attacks. Stored procs can also be secured at the server so if your app uses Windows authentication to grant access to SQL Server a user who is not authorized won't be able to run the proc, even if not using Windows authentication, different users, or groups of users can be secured.


        only two letters away from being an asset

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups