473,396 Members | 1,997 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,396 software developers and data experts.

Querying data: Stored procedures or Select calls from C# class?

VM
I'm working on a win appication that is constantly querying a small-sized
DB. Until now, I've been using Selects from within my app but, all of a
sudden I remembered of an application I was working on a year ago (with
PowerBuilder) that queried the DB by invoking stored procedures that return
the data to the application. One of the main problems was that there were
over 100 SPs so it was pretty difficult to maintain. So my question: Is it
better to place my SQL queries into SPs and call them from within my
application or should I just retrieve the data by using queries from the
application? I created a class specifically to call methods that access the
DB so any maintenance would be here.

Thanks.
Nov 15 '05 #1
1 1531
In general, SP's are much better. 1) You can fix the proc without
recompiling your app 2) SECURITY (which should probably be 1) 3) less code
4) Performance.

I have a web app that I load users into a table and corresponding stored
procs that go with their role in another table. So I can use a Generic proc
to find out all of the information I need to dynamically populate things for
them. using ExecuteScalar, I can return the proc name that I need at any
given time and use use that value in turn to run other procs. I can fulfill
user request changes while I'm on the phone with them totally transparent to
them. This could not be done with Dynamic SQL. Maintenance is simple and
it scales very well. THe same code set that originally had 25 users now
works for over 350...and it's not b/c my design was that great, it's just
that using procs to retrieve other ones, and in some cases create new ones,
is a very flexible approach.

One thing you may want to consider for Parameterized procs. You can have
the proc name and an arraylist with parameters in the function signature of
whatever your DataAccess layer is. If the ArrayList.COunt is 0, then don't
add any params. Otherwise, clear the existing parameters collection and
iteratively add the values to the params collection. If you use an array or
hashtable for instnace, you can still use an interative approach to use
named params with their corresponding values and DataTypes.

I know there are many out there who are dyed in the wool Dynamic SQL
advocates, but IMHO, using Procs is better in every important way.

Cheers,

Bill

I'm probably opening up a can of worms here
"VM" <vo******@yahoo.com> wrote in message
news:eH*************@TK2MSFTNGP09.phx.gbl...
I'm working on a win appication that is constantly querying a small-sized
DB. Until now, I've been using Selects from within my app but, all of a
sudden I remembered of an application I was working on a year ago (with
PowerBuilder) that queried the DB by invoking stored procedures that return the data to the application. One of the main problems was that there were
over 100 SPs so it was pretty difficult to maintain. So my question: Is it better to place my SQL queries into SPs and call them from within my
application or should I just retrieve the data by using queries from the
application? I created a class specifically to call methods that access the DB so any maintenance would be here.

Thanks.

Nov 15 '05 #2

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

Similar topics

3
by: Hursh | last post by:
Hi, I have written some stored procedures in SQL and these procedures return some value. I want these values to be captured by the ASP code. I am able to access the tables using ADO(...
2
by: Naren | last post by:
Hi, I am a newbie to Oracle and stored procedures. Hence this question comes up. The complete scenario is like this. We have a multithreaded application using pthreads on HP-UX machine. We are...
1
by: Ryan | last post by:
We have a suppliers application that runs a stored procedure (one of many). This stored procedure then calls various other ones etc... and the final number of stored procedures run is 11. Now,...
0
by: sedefo | last post by:
I ran into this Microsoft Patterns & Practices Enterprise Library while i was researching how i can write a database independent data access layer. In my company we already use Data Access...
2
by: Phil | last post by:
I have the following code but do not know the best way to return the updated DataTable back to the database. I believe I can use the Update method of the Data Adapter, BUT if true, I also believe I...
7
by: Marc Pelletier | last post by:
Hello, I have a table with a Day field, defined as smalldatetime. I am filling it from a CSharp application with the following code: DataRow r = dtStaDays.NewRow(); r= station_ID; r =...
2
by: Abhishek Srivastava | last post by:
Hello All, Suppose if I have a SQL query like select p.ID, p.NAME, p.UNIT_PRICE, o.QUANTITY from PRODUCT p ORDERS o where p.ID = X AND P.ID = O.ID Here one product can have many orders....
3
by: markaelkins | last post by:
I want to create a simple user interface to collect the following data and store the data in a SQL database…. Could someone please help me get started? Data to collect from user interface and...
3
by: MDB | last post by:
I'd normally Google for a question like this, and hope to snag a few examples along with the answer, but this time I can't see to get the keywords specific enough. Or I'd ask coworkers, but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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,...

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.