473,386 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Stored procedures vs. command strings in c#...

My boss wants me to use stored procedures, but I thought somehow that
using c# that
ADO.Net was better. Any help is appreciated.
Thanks,
Trint

Nov 16 '05 #1
7 1700
Hi Trint,

Using stored procedures there is less data that needs to be transfered
over the net as the data is processed on the sql server and only the
result is returned. Lower bandwith needed and faster result :)

On 17 Jan 2005 04:48:47 -0800, trint <tr***********@gmail.com> wrote:
My boss wants me to use stored procedures, but I thought somehow that
using c# that
ADO.Net was better. Any help is appreciated.
Thanks,
Trint


--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
Hi,

I guess its all a matter of personal preference really. I think the
general consensus that the best practices is to use stored procs.

The advantage of stored procs is that they're compiled (I believe), and
hence run much faster than a query passed in a string. Plus as they are
doing mainly direct database actions it makes sense that they sit
within the database server.

However, if you are doing many calls to the db server, it may make
sense to wrap the query up into one string and pass that, as the db
server round-trips can be a bottle-neck.

Also, stored procs don't have source control, unlike c# code can have.

Personally I sit in the use stored procs camp. I believe database
functions should sit as close to the db as possible. Plus, you can
still use ADO.NET and all it's functionality with stored procedures -
the only difference being you pass a stored proc name rather than a
string of sql.

I know some developers who prefer using sql queries within their code,
but as far as I can tell it's purely because that's the environment
they are used to and like - unlike sql enterprise manager.

My tuppence worth... hope it's of some help...
Regards,

Peter Chadwick (MCP)
pe**@code-explorers.com

Nov 16 '05 #3
Thanks,
I am sure that a guy with the compay who installed our report services
told me that if the procedure had a 'where' clause in it, report
services had to recompile it anyway...but...stored procs it is.
trint

Nov 16 '05 #4
Trint,

I think almost the same as Peter, where I think for
production: command stored procedure
developing: command Strings

Have a look as well for this probably makes it all clear.
http://msdn.microsoft.com/library/de...dtexttopic.asp

Just my thought,

Cor
Nov 16 '05 #5
Peter Chadwick (MCP) wrote:
I guess its all a matter of personal preference really. I think the
general consensus that the best practices is to use stored procs.
no, it's a myth that stored procs are 'better'.
The advantage of stored procs is that they're compiled (I believe), and
no they're not compiled, at least not on SqlServer. On DB2 they're
generated as C code which is compiled but on SqlServer and also on
Oracle, they're not compiled, but stored as is and when executed they're
compiled and the EXECUTION plan is cached. The same is done with a
parameterizied query. This means that the second time a parameterized
query is executed, it's cached execution plan is used, it's not recompiled.
hence run much faster than a query passed in a string. Plus as they are
doing mainly direct database actions it makes sense that they sit
within the database server.
Only if they are not used for CRUD operations. Procs for CRUD are more
of a burden than a help. Long running data munching procs are better
suitable in procedure form in the database, however not a lot of systems
needs these.
However, if you are doing many calls to the db server, it may make
sense to wrap the query up into one string and pass that, as the db
server round-trips can be a bottle-neck.

Also, stored procs don't have source control, unlike c# code can have.


Most DBA's write their scripts first in textfiles and store these in
sourcecontrol :)

Frans

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Nov 16 '05 #6
If you create a well defined DB Layer for your application then yes, use
C# and keep all the DB logic out of the db.

The stored procs scatter your appliaction logic.

The Stored Procedures are good for DB Developers, where they can massage
the data all they want without any proper understanding of why the data
is being massaged.

The good thing about Stored Procedures is that they are for DataBase
side not the application side of the system.

Cheers
trint wrote:
My boss wants me to use stored procedures, but I thought somehow that
using c# that
ADO.Net was better. Any help is appreciated.
Thanks,
Trint

Nov 16 '05 #7
Frans,
no, it's a myth that stored procs are 'better'.


Better is a subjective word.

Being in the sun on the "Pier" is found by most people better than in the
rain, however there are as well fishermain who wants to do that in the rain
and find that better.

:-)

Cor
Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Shaun Stuart | last post by:
I've got a webpage that calls some stored procedures with input variables. The procedures return recordsets and also some output variables. We're trying to get the values of the output variables....
4
by: Minh Tran | last post by:
In order to minimize the number of connection strings I have to use to access different databases on the same Sql Server, I was considering storing all stored procedures in just one database. I...
11
by: Bã§TãRÐ | last post by:
I have been working on this particular project for a little over 2 weeks now. This product contains between 700-900 stored procedures to handle just about all you can imagine within the product. I...
7
by: Alex | last post by:
Hi all, I am trying to install a java stored procedure via the windows development centre. The linux box is running 8.1 FP4 as is the windoze platform. If I am on the linux box i can install...
3
by: Rhino | last post by:
I've spent the last couple of hours trying to figure out how to debug a Java stored procedure and am just going in circles. The last straw came when I got "Cannot open input stream for default"...
3
by: Samarth | last post by:
Folks, I am calling a DB2 stored procedure through Perl using the DBI:ODBC module. I am not sure if I can do this or not because I have been able to connect to and also issue select statements...
4
by: scparker | last post by:
Hello, We have a stored procedure that does a basic insert of values. I am then able to retrieve the ID number created for this new record. We are currently using ASP.NET 2.0 and use N-Tier...
2
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
11
by: peter | last post by:
I am trying to get a SQL stored procedure to use user maintained MQT implicitly which raises questions on when they are used or not used. In theory you would expect the stored procedure to pick up...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.