473,756 Members | 4,256 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why use stored procedure in C#?

Hi,

In my C# Windows Form application project, I have done all queries on my
codes.
Now I wanna try using the Stored Procedure.
But I am not clear about why using the stored procedure.
Would some one give me some advice?
Thanks for help.

Jason
Mar 23 '06 #1
12 2298

"Jason Huang" <Ja************ @hotmail.com> wrote in message
news:eC******** *****@TK2MSFTNG P10.phx.gbl...
Hi,

In my C# Windows Form application project, I have done all queries on my
codes.
Now I wanna try using the Stored Procedure.
But I am not clear about why using the stored procedure.
Would some one give me some advice?
Thanks for help.


1. To isolate the app from the database schema.
2. To allow simulation of inheritance and other OO features in the database
(i.e. a derived class will typically map to two tables and SPs can hide
this)
3. To allow the app to have access restricted to only those operations and
data that it needs.
Mar 23 '06 #2
Seems very comprehensive!
"Nick Hounsome" <nh***@nickhoun some.me.uk> ¼¶¼g©ó¶l¥ó·s»D: SX************* ********@fe1.ne ws.blueyonder.c o.uk...

"Jason Huang" <Ja************ @hotmail.com> wrote in message
news:eC******** *****@TK2MSFTNG P10.phx.gbl...
Hi,

In my C# Windows Form application project, I have done all queries on my
codes.
Now I wanna try using the Stored Procedure.
But I am not clear about why using the stored procedure.
Would some one give me some advice?
Thanks for help.


1. To isolate the app from the database schema.
2. To allow simulation of inheritance and other OO features in the
database (i.e. a derived class will typically map to two tables and SPs
can hide this)
3. To allow the app to have access restricted to only those operations and
data that it needs.

Mar 23 '06 #3
Nick Hounsome wrote:

"Jason Huang" <Ja************ @hotmail.com> wrote in message
news:eC******** *****@TK2MSFTNG P10.phx.gbl...
Hi,

In my C# Windows Form application project, I have done all queries
on my codes.
Now I wanna try using the Stored Procedure.
But I am not clear about why using the stored procedure.
Would some one give me some advice?
Thanks for help.
1. To isolate the app from the database schema.


since when do you need a proc for that?
2. To allow simulation of inheritance and other OO features in the
database (i.e. a derived class will typically map to two tables and
SPs can hide this)
I can do that perfectly fine without a proc. If you truly want it
inside the db, you can also do it with a view. A view is even more
practical as well, as you don't have to hardcode filter statements in
the proc.
3. To allow the app to have access restricted to only those
operations and data that it needs.


you can also do that with different methods. (role based security).

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Mar 23 '06 #4
Nick,

a couple of very good reason for using stored procedures rather than SQL
Statements coded in code are.

1) The processing of the query is done by the server where the stored
procedure is located, thus, in theory speeding up processing times. Now if
your running one or 2 statements you might not notice this, but if your
running hundreds of thousands of transaction an hour, then you will notice
the time saving.

2) If there is a bug in your SQL statement it is quite easy to fix these
within a stored procedure without having to recompile your app and then
redistribute it to the client.

Regards
Scott Blood
C# Developer
"Nick Hounsome" <nh***@nickhoun some.me.uk> wrote in message
news:SX******** *************@f e1.news.blueyon der.co.uk...

"Jason Huang" <Ja************ @hotmail.com> wrote in message
news:eC******** *****@TK2MSFTNG P10.phx.gbl...
Hi,

In my C# Windows Form application project, I have done all queries on my
codes.
Now I wanna try using the Stored Procedure.
But I am not clear about why using the stored procedure.
Would some one give me some advice?
Thanks for help.


1. To isolate the app from the database schema.
2. To allow simulation of inheritance and other OO features in the
database (i.e. a derived class will typically map to two tables and SPs
can hide this)
3. To allow the app to have access restricted to only those operations and
data that it needs.

Mar 23 '06 #5

"Frans Bouma [C# MVP]" <pe************ ******@xs4all.n l> wrote in message
news:xn******** *******@news.mi crosoft.com...
Nick Hounsome wrote:

"Jason Huang" <Ja************ @hotmail.com> wrote in message
news:eC******** *****@TK2MSFTNG P10.phx.gbl...
> Hi,
>
> In my C# Windows Form application project, I have done all queries
> on my codes.
> Now I wanna try using the Stored Procedure.
> But I am not clear about why using the stored procedure.
> Would some one give me some advice?
> Thanks for help.
1. To isolate the app from the database schema.


since when do you need a proc for that?


How else?
2. To allow simulation of inheritance and other OO features in the
database (i.e. a derived class will typically map to two tables and
SPs can hide this)


I can do that perfectly fine without a proc. If you truly want it
inside the db, you can also do it with a view. A view is even more
practical as well, as you don't have to hardcode filter statements in
the proc.


Additions and updates can be a problem through a view.
3. To allow the app to have access restricted to only those
operations and data that it needs.


you can also do that with different methods. (role based security).


Much harder to set up, document and maintain.
Mar 23 '06 #6
"Jason Huang" <Ja************ @hotmail.com> wrote in message
news:eC******** *****@TK2MSFTNG P10.phx.gbl...
But I am not clear about why using the stored procedure.


http://www.google.com/search?sourcei...dynamic+SQL%22
Mar 23 '06 #7
>> I can do that perfectly fine without a proc. If you truly want it
inside the db, you can also do it with a view. A view is even more
practical as well, as you don't have to hardcode filter statements in
the proc.

Additions and updates can be a problem through a view.


Well, I think we're talking about apples and oranges here. Using a DataSet
and a set of views *can be* quite useful. But not for everything. So, I
don't think we need to debate on the usefulness of DataSets and Views, but
it is certain that they are not useful for everything. I believe the real
issue here is using Stored Procedures versus hard-coded SQL statements in
the business logic. And it is inarguable that Stored Procedures are far
superior to inline SQL statements for all the reasons originally stated.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"Nick Hounsome" <nh***@nickhoun some.me.uk> wrote in message
news:9f******** ************@fe 2.news.blueyond er.co.uk...
"Frans Bouma [C# MVP]" <pe************ ******@xs4all.n l> wrote in message
news:xn******** *******@news.mi crosoft.com...
Nick Hounsome wrote:

"Jason Huang" <Ja************ @hotmail.com> wrote in message
news:eC******** *****@TK2MSFTNG P10.phx.gbl...
> Hi,
>
> In my C# Windows Form application project, I have done all queries
> on my codes.
> Now I wanna try using the Stored Procedure.
> But I am not clear about why using the stored procedure.
> Would some one give me some advice?
> Thanks for help.

1. To isolate the app from the database schema.


since when do you need a proc for that?


How else?
2. To allow simulation of inheritance and other OO features in the
database (i.e. a derived class will typically map to two tables and
SPs can hide this)


I can do that perfectly fine without a proc. If you truly want it
inside the db, you can also do it with a view. A view is even more
practical as well, as you don't have to hardcode filter statements in
the proc.


Additions and updates can be a problem through a view.
3. To allow the app to have access restricted to only those
operations and data that it needs.


you can also do that with different methods. (role based security).


Much harder to set up, document and maintain.

Mar 23 '06 #8
Wow... finally a sensible discussion about SP vs inline dynamic. I get soooo
fed up with hearing developers saying how much quicker SP's are compared to
inline sql when in fact in 90%+ of cases the difference is nano-seconds. But
yes there are other advantages which have been very elequently pointed out.
However, there are advantages to dynamic inline sql.

I recently built a framework for an NHS trust where they wanted to be able
to have classes that they specify the tablename and field names that they are
interested in and the framework would generate a class based on those
properties, in this instance you can ONLY achieve this with dynamic inline
sql as the connection string was specified in the constructor of the class
and could be changed at runtime, therefore there is no way that you could use
sp's as you would have to deploy the sp's to the databae before you could use
it.

Also for lookup data, dynamic sql is far, far simpler. In a previous job a
guy we will call JimBob wrote an sp which depending on what type of lookup
you were looking for built up a sql string inside the stored proc to select
the various fields from the various tables, however, it was a nightmare as he
had so many double quotes to worry about that it ended up working brilliantly
until one day someone entered something with 3 single quotes in one of the
fields, which totally fubar'd it all and by the time he had written all the
checking etc into the SP it was totally unmaintainable by anyone but him.

One of the other advantages of SP's over inline is the fact you can create
global temporary tables and use cursors etc, which I'm sure is probably
possible with inline, but it would be very, very messy.

So as you have probably gathered yourself by now, it is a case, as with so
many development theologies of horses for courses, there are some situations
where inline is better, some situations where SP's are better, and some
situations where it makes no difference at all and is entirely down to what
you / the organisation prefer.

Cheerio

Ian
"Nick Hounsome" wrote:

"Frans Bouma [C# MVP]" <pe************ ******@xs4all.n l> wrote in message
news:xn******** *******@news.mi crosoft.com...
Nick Hounsome wrote:

"Jason Huang" <Ja************ @hotmail.com> wrote in message
news:eC******** *****@TK2MSFTNG P10.phx.gbl...
> Hi,
>
> In my C# Windows Form application project, I have done all queries
> on my codes.
> Now I wanna try using the Stored Procedure.
> But I am not clear about why using the stored procedure.
> Would some one give me some advice?
> Thanks for help.

1. To isolate the app from the database schema.


since when do you need a proc for that?


How else?
2. To allow simulation of inheritance and other OO features in the
database (i.e. a derived class will typically map to two tables and
SPs can hide this)


I can do that perfectly fine without a proc. If you truly want it
inside the db, you can also do it with a view. A view is even more
practical as well, as you don't have to hardcode filter statements in
the proc.


Additions and updates can be a problem through a view.
3. To allow the app to have access restricted to only those
operations and data that it needs.


you can also do that with different methods. (role based security).


Much harder to set up, document and maintain.

Mar 23 '06 #9

"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in message
news:Oo******** ******@tk2msftn gp13.phx.gbl...
"Jason Huang" <Ja************ @hotmail.com> wrote in message
news:eC******** *****@TK2MSFTNG P10.phx.gbl...
But I am not clear about why using the stored procedure.


http://www.google.com/search?sourcei...dynamic+SQL%22


An interesting discussion.

I think that the disagreements come about because of differences in the type
of application that people have worked on.

If the application drives the database design then it is true that SPs are
less useful but if you are in the situation where there is a database and
all you can do is request access to it then SPs look much more appealing.
When you work on an app where you have a database and several independent
apps all be upgraded more or less independently SPs are the only way to go.
Mar 24 '06 #10

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

Similar topics

3
22145
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my application server can talk to the database. I've determined the failure occurs when the the following statement is executed: cstmt.execute(); (due to the failure of println statements placed afterwards). I get the following error after trying to...
0
6703
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft Visual Basic .NET version of this article, see 308049. For a Microsoft Visual C++ .NET version of this article, see 310071. For a Microsoft Visual J# .NET version of this article, see 320627. This article refers to the following Microsoft .NET...
3
2805
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" when I launched the IBM Distributed Debugger via D:\IBMDebug>idebug.exe -qdaemon -quiport=8000,8001 First, a bit of background. I am running DB2 V7.2 with Fixpack 9 applied on Windows XP Professional (all critical service applied). I've written...
4
3190
by: Rhino | last post by:
Is it possible for a Java Stored Procedure in DB2 V7.2 (Windows) to pass a Throwable back to the calling program as an OUT parameter? If yes, what datatype should I use when registering the Throwable as an OUT parameter and what datatype should I use in the CREATE PROCEDURE and DROP PROCEDURE statements? Here's what I tried: - the method signature for the stored procedure included: Throwable throwable
8
7944
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have created a temporary database with a tables space. Verified that DECLARE GLOBAL TEMPORARY TABLE TEMP (A INTEGER); INSERT INTO SESSION.TEMP VALUES(10); SELECT A FROM SESSION.TEMP; works from a query tool.
2
5458
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
0
2653
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how to call them from an ASP.Net page Every modern database system has a stored procedure language. SQL Server is no different and has a relatively sophisticated and easy to use system. This article will not attempt to go into depth in explaining...
3
3476
by: kd | last post by:
Hi All, How to debug a stored procedure? Thanks, kd
7
3469
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function 'UpdateRegistrant' expects parameter '@EMail', which was not supplied. The field value was null in the database and not changed in the FormView so is null going back into the stored procedure. I'm stumped and would greatly appreciate any suggestions.
2
4108
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
0
9462
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10046
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9886
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9722
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8723
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6542
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2677
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.