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

Stored Procedure with parameters Vs direct Query

Hi guys,

1. In my application,to Connect to DB, i used to write direct string queries in any function, assigning them appropriate variables using '+' sign. Then I had separate Data Access class to which I used to pass this query where it used to get executed.Code was like this:

Expand|Select|Wrap|Line Numbers
  1.   void someFunction()
  2.      { 
  3.           clsDatabase objDB = new clsDatabase();
  4.           strSQL = "INSERT INTO QUERY"+param1;
  5.           objDB.ProcessQuery(strSQL);
  6.      }
Now, I have changed my way, I have written a stored procedure with parameters. I call a function of Data Access class which calls this stored procedure. I pass parameters to function which are assigned to strored procedure parameters.

Expand|Select|Wrap|Line Numbers
  1.   void someFunction()
  2.      { 
  3.           clsDatabase objDB = new clsDatabase();
  4.           objDB.functionWhichCallsStoredParameters(param1);
  5.      }
Both approches work, but i want to know which one is good & faster.

2. Second Thing I want to know is, In one of my classes, I m making object of ClsDatabase in static method. I think its gonna use same objects again & again, creating problems for concurrency.Plz, clarify.

Expand|Select|Wrap|Line Numbers
  1.   static void someFunction()
  2.      { 
  3.           clsDatabase objDB = new clsDatabase();
  4.           objDB.functionWhichCallsStoredParameters(param1);
  5.      }

Thanks in advance.
Apr 27 '10 #1
3 2489
Please, Let me know if my question is not clear to u guys...no reply so far...???
Apr 27 '10 #2
ck9663
2,878 Expert 2GB
On your first question, the second one, by default is usually faster.Even if the query are exactly the same. This is because SQL Server stores the way it executed the stored procedure using the optimizer. If you use a dynamic sql, it will run it as if it is executed the first time and the way it will be executed might not always be the most efficient way to execute the query.

Your second question is more of a front-end question than a back-end question.

Happy Coding!!!

~~ CK
Apr 27 '10 #3
debasisdas
8,127 Expert 4TB
In any database the stored procedure is a pre-compiled object. The SQL part in the stored procedure is not parsed / compiled at run time which is thecase with any raw SQL. Thats why stored procedure will always give you better performance.
Apr 28 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
3
by: Michael | last post by:
This one's really got me. I have a VB.NET (version 1.1.4322) project that provides an easy way to execute stored procedures on a generic level. When I run the code on computer A (running SQL...
1
by: Aston | last post by:
I have this stored procedure that takes a few parameters like date and merchant ID, and basically goes through a set of if-then statements to build a SQL SELECT string. When we upgraded from SQL...
0
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...
7
by: Douglas Buchanan | last post by:
I can't seem to open SQLS2k Stored Procedures in the IDE I am running MDE 2003 Version 7.1.3088 I have a MSDN professional subscription and did a complete install of vs.net Help explains how...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
1
by: Justin | last post by:
I am trying to query two tables with a stored procedure but I get the following error: "Procedure Details has no parameters and arguments were supplied." Here is my stored procedure as created...
7
by: JIM.H. | last post by:
Hello, Is there any difference to between SLQ string in the code and call execute query and call a stored procedure and execute the query that way concerning speed, effectiveness, reliability,...
5
by: ric_deez | last post by:
Hi there, I would like to create a simple search form to allow users to search for a job number based on a number of parameters. I think I understand how to use parameteres associated with Stored...
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
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,...
1
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...
0
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...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.