473,667 Members | 2,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1544
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******** *****@TK2MSFTNG P09.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
2332
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( recordsets ) but is there a way to pass data returned from stored procedures to vairables in ASP code.
2
40665
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 connecting to Oracle database 8.1.7. The application calls stored procedures on database using OCI calls. It is also ensured that the our application is thread safe. When a particular procedure is called, a SQL select statment returns
1
2270
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, some of our users have been having problems and deciding for themselves to CTRL+ALT+DEL the application. This is the first thing we will stop. However, we have had some error messages indicating that the previous transaction is blocking them...
0
5395
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 Application Block (DAAB) in our .Net projects. We use SqlHelper in SQL based projects, and OracleHelper in Oracle based ones. OracleHelper was not published officially by Microsoft as part of the DAAB but it was given as a helper code in a sample .Net...
2
1425
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 have to 'long-hand' write code for each individual column data that's being added......this seems a bit daft considering that the data is already in the disconnected data table. Have I lost the plot?? Based on the code below, what is the correct...
7
32948
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 = sd.Date; r = rangeTide; etc.
2
2448
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. Essentially Product is the master table and Orders is the details table.
3
3129
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 store in database: tDateS (trade date sell) tDateB (trade date buy) contracts (number of contracts) strike (stike price) sValue (sell value) bValue (buy value)
3
1577
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 they're just as new to ASP.NET as I am. Is it possible to have a dataset filled with all the records in an SQL table (on the small side, maybe three hundred records total), and then query that table for subsets of data, e.q. a simple WHERE clause,...
0
8458
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
8366
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8790
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...
1
8565
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8650
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
5677
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
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2779
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1779
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.