Stored Procedures vs Ad Hoc SQL

Stored procedures debate from my point of view:

Pros of using Stored Procedures

Cons of using Stored Procedures

I’m not entirely sure which side of the fence I lie.  Right now I’m more comfortable with not using stored procedures because of the maintenance factor.  I really think LINQ is going to make stored procedures deprecated.

.NET specific - Here is a nice line of code to keep around when working with stored procedures that I end up using when getting the the dreaded “Parameters do not match” error.  You can put this on your datasource Inserting Event.

For x As Integer = 0 To e.Command.Parameters.Count - 1

Trace.Write(e.Command.Parameters(x).ParameterName)

Trace.Write(e.Command.Parameters(x).Value)

Next

Written by Tim on June 1st, 2007 with 6 comments.
Read more articles on asp.net and database.



Related articles

6 comments

Read the comments left by other users below, or:

Get your own gravatar by visiting gravatar.com Corwin
#1. July 26th, 2007, at 7:06 PM.

You can create test harnesses to test/debug the procs. And if you include tons of commmented out tests in the harness, you can easily retest portions as needed. Stored procs should contain an error handling routine that passes back something better than 512.

Embrace it, logic in the database is a good thing.

Get your own gravatar by visiting gravatar.com website design hampshire
#2. December 18th, 2010, at 8:53 AM.

When dealing with the maintenance issue, having a central location for dealing with data and only data, increases the ease of maintenance. Let’s take for instance, calculated data (cola + colb / colc). In an ad hoc situation, your calculation is created and ran by the user / application. Each user / application could calculate the same metric differently (both (cola + colb) / colc or the previous example). Whereas, sprocs (or even views) help eliminate that problem. Additionally, should the calculation be wrong, you no longer have to update the application, you only have to update the sproc. Because remember, when you update the application, you then have to deal with redeployment of that app.

Get your own gravatar by visiting gravatar.com web marketing melbourne
#3. December 21st, 2010, at 4:53 AM.

There is an argument I didn’t find in your article: by implementing (some or all of) the business logic in stored procedures, you allow to reuse that business logic from *all* the layers above. In some cases, that can be extremely useful. I work on medical applications that always have to integrate with some legacy code, sometimes running on very exotic platforms/environments. Tough (or impossible) to call .NET/COM/whatever code running on a middle tier from there, but usually OK to call SPs directly. Having most of the business rules at the database level ensures that whatever the call context (from middle tier or from a legacy application), the same rules will apply.

Get your own gravatar by visiting gravatar.com current affairs
#4. April 1st, 2011, at 5:40 AM.

Excellent post. I’m actually surprised the use of blogs and wikis isn’t higher.

Get your own gravatar by visiting gravatar.com christian louboutin
#5. April 2nd, 2011, at 8:57 AM.

http://www.fashionchristianlouboutinshoes.com/
christian louboutin is the symbol of women.
It is said that a woman without christian louboutin sales knows nothing about fashion.
That is right.If you want to be fashionable.Please christian louboutin shoes.

Get your own gravatar by visiting gravatar.com sunglass hut
#6. October 31st, 2011, at 9:22 AM.

I know, I always live in the memories, I know, I always remember the past, I know, forget you have to forget.

Leave your comment...

If you want to leave your comment on this article, simply fill out the next form:




Anti-Spam Protection by WP-SpamFree

You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> .

Famous Homemade Soups