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

Best practice

Hello All,

Best coding strategies for calling stored procedures from ASP.NET. As you
are all aware that accessing a property is expensive than calling a method.
For example in order to call a stored procedure which accepts 2 input
parameters, we are currently following the below standard to set a single
parameter:

objOracleParameterSTATUS = new System.Data.OracleClient.OracleParameter ();
objOracleParameterSTATUS.ParameterName ="STATUS_IN";
objOracleParameterSTATUS.SourceColumn = "STATUS"
objOracleParameterSTATUS.OracleType=System.Data.Or acleClient.OracleType.Number;
objOracleParameterSTATUS.Size =1;
objOracleParameterSTATUS.Precision =0;
objOracleParameterSTATUS.Scale =0;
objOracleParameterSTATUS.Direction = System.Data.ParameterDirection.Input;
objOracleParameterSTATUS.SourceVersion=System.Data .DataRowVersion.Current;
objOracleParameterSTATUS.Value =STATUS;
bjOracleCommand.Parameters.Add (objOracleParameterSTATUS);

So on the whole we are setting 9 properties for a single parameter and if
this stored procedure accepts 10 parameters, then this process has to be
repeated for those many parameters.

Can any of the solution developers suggest me an alternative choice for the
above code or how can I make this less expensive and efficient.

Thanks for your help!!!
Nov 19 '05 #1
6 1907
If that object has no method to set all of them, then there is nothing you
can do.

I honestly don't think you are going to see an actual performance problem by
having to set 9 properties instead of calling 1 method.

"Diffident" <Di*******@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.com...
Hello All,

Best coding strategies for calling stored procedures from ASP.NET. As you
are all aware that accessing a property is expensive than calling a
method.
For example in order to call a stored procedure which accepts 2 input
parameters, we are currently following the below standard to set a single
parameter:

objOracleParameterSTATUS = new System.Data.OracleClient.OracleParameter
();
objOracleParameterSTATUS.ParameterName ="STATUS_IN";
objOracleParameterSTATUS.SourceColumn = "STATUS";
objOracleParameterSTATUS.OracleType=System.Data.Or acleClient.OracleType.Number;
objOracleParameterSTATUS.Size =1;
objOracleParameterSTATUS.Precision =0;
objOracleParameterSTATUS.Scale =0;
objOracleParameterSTATUS.Direction = System.Data.ParameterDirection.Input;
objOracleParameterSTATUS.SourceVersion=System.Data .DataRowVersion.Current;
objOracleParameterSTATUS.Value =STATUS;
bjOracleCommand.Parameters.Add (objOracleParameterSTATUS);

So on the whole we are setting 9 properties for a single parameter and if
this stored procedure accepts 10 parameters, then this process has to be
repeated for those many parameters.

Can any of the solution developers suggest me an alternative choice for
the
above code or how can I make this less expensive and efficient.

Thanks for your help!!!

Nov 19 '05 #2
Property getters and setters are generally short enough to be inlined
by the optimizing compiler, so they won't be as expensive as a method
call. No need to worry....

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 13 May 2005 12:41:11 -0700, Diffident
<Di*******@discussions.microsoft.com> wrote:
Hello All,

Best coding strategies for calling stored procedures from ASP.NET. As you
are all aware that accessing a property is expensive than calling a method.
For example in order to call a stored procedure which accepts 2 input
parameters, we are currently following the below standard to set a single
parameter:

objOracleParameterSTATUS = new System.Data.OracleClient.OracleParameter ();
objOracleParameterSTATUS.ParameterName ="STATUS_IN";
objOracleParameterSTATUS.SourceColumn = "STATUS";
objOracleParameterSTATUS.OracleType=System.Data.O racleClient.OracleType.Number;
objOracleParameterSTATUS.Size =1;
objOracleParameterSTATUS.Precision =0;
objOracleParameterSTATUS.Scale =0;
objOracleParameterSTATUS.Direction = System.Data.ParameterDirection.Input;
objOracleParameterSTATUS.SourceVersion=System.Dat a.DataRowVersion.Current;
objOracleParameterSTATUS.Value =STATUS;
bjOracleCommand.Parameters.Add (objOracleParameterSTATUS);

So on the whole we are setting 9 properties for a single parameter and if
this stored procedure accepts 10 parameters, then this process has to be
repeated for those many parameters.

Can any of the solution developers suggest me an alternative choice for the
above code or how can I make this less expensive and efficient.

Thanks for your help!!!


Nov 19 '05 #3

Instead of coding these many lines for each and every parameter, is there
anyway that I can reduce the lines of code ? How can I design a resusable
method for setting these properties......so that this method can be called
for each and every parameter?

"Scott Allen" wrote:
Property getters and setters are generally short enough to be inlined
by the optimizing compiler, so they won't be as expensive as a method
call. No need to worry....

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 13 May 2005 12:41:11 -0700, Diffident
<Di*******@discussions.microsoft.com> wrote:
Hello All,

Best coding strategies for calling stored procedures from ASP.NET. As you
are all aware that accessing a property is expensive than calling a method.
For example in order to call a stored procedure which accepts 2 input
parameters, we are currently following the below standard to set a single
parameter:

objOracleParameterSTATUS = new System.Data.OracleClient.OracleParameter ();
objOracleParameterSTATUS.ParameterName ="STATUS_IN";
objOracleParameterSTATUS.SourceColumn = "STATUS";
objOracleParameterSTATUS.OracleType=System.Data.O racleClient.OracleType.Number;
objOracleParameterSTATUS.Size =1;
objOracleParameterSTATUS.Precision =0;
objOracleParameterSTATUS.Scale =0;
objOracleParameterSTATUS.Direction = System.Data.ParameterDirection.Input;
objOracleParameterSTATUS.SourceVersion=System.Dat a.DataRowVersion.Current;
objOracleParameterSTATUS.Value =STATUS;
bjOracleCommand.Parameters.Add (objOracleParameterSTATUS);

So on the whole we are setting 9 properties for a single parameter and if
this stored procedure accepts 10 parameters, then this process has to be
repeated for those many parameters.

Can any of the solution developers suggest me an alternative choice for the
above code or how can I make this less expensive and efficient.

Thanks for your help!!!


Nov 19 '05 #4
Hi,

actually I do not know the OracleClient - but I am sure, the Oracle Provider
provides an overloaded constructor for the OracleParameter Object (this is
available for the SQL-Server Client at last).

This is the way, I solve this for a SQL-Server sp parameter:

(Please note: the SqlParameter has 6 different constructors. One of them can
handle all the properties you are using - like
Direction,Scale,Precision,Size, etc)

myCommand.Parameters.Add(New SqlClient.SqlParameter("@PKClientGuid",
SqlDbType.UniqueIdentifier)).Value = Client.Guid

I think this is much more read- and maintainable.

Hope I could help you!

Regards,

Tom

"Diffident" <Di*******@discussions.microsoft.com> schrieb im Newsbeitrag
news:9C**********************************@microsof t.com...
Hello All,

Best coding strategies for calling stored procedures from ASP.NET. As you
are all aware that accessing a property is expensive than calling a
method.
For example in order to call a stored procedure which accepts 2 input
parameters, we are currently following the below standard to set a single
parameter:

objOracleParameterSTATUS = new System.Data.OracleClient.OracleParameter
();
objOracleParameterSTATUS.ParameterName ="STATUS_IN";
objOracleParameterSTATUS.SourceColumn = "STATUS";
objOracleParameterSTATUS.OracleType=System.Data.Or acleClient.OracleType.Number;
objOracleParameterSTATUS.Size =1;
objOracleParameterSTATUS.Precision =0;
objOracleParameterSTATUS.Scale =0;
objOracleParameterSTATUS.Direction = System.Data.ParameterDirection.Input;
objOracleParameterSTATUS.SourceVersion=System.Data .DataRowVersion.Current;
objOracleParameterSTATUS.Value =STATUS;
bjOracleCommand.Parameters.Add (objOracleParameterSTATUS);

So on the whole we are setting 9 properties for a single parameter and if
this stored procedure accepts 10 parameters, then this process has to be
repeated for those many parameters.

Can any of the solution developers suggest me an alternative choice for
the
above code or how can I make this less expensive and efficient.

Thanks for your help!!!

Nov 19 '05 #5
Boilerplate data access code such as this can be dramatically simplified by
using Microsoft's free Data Access Application Block.
Here's more info:
http://aspnet.4guysfromrolla.com/articles/070203-1.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Diffident" <Di*******@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.com...
Hello All,

Best coding strategies for calling stored procedures from ASP.NET. As you
are all aware that accessing a property is expensive than calling a
method.
For example in order to call a stored procedure which accepts 2 input
parameters, we are currently following the below standard to set a single
parameter:

objOracleParameterSTATUS = new System.Data.OracleClient.OracleParameter
();
objOracleParameterSTATUS.ParameterName ="STATUS_IN";
objOracleParameterSTATUS.SourceColumn = "STATUS";
objOracleParameterSTATUS.OracleType=System.Data.Or acleClient.OracleType.Number;
objOracleParameterSTATUS.Size =1;
objOracleParameterSTATUS.Precision =0;
objOracleParameterSTATUS.Scale =0;
objOracleParameterSTATUS.Direction = System.Data.ParameterDirection.Input;
objOracleParameterSTATUS.SourceVersion=System.Data .DataRowVersion.Current;
objOracleParameterSTATUS.Value =STATUS;
bjOracleCommand.Parameters.Add (objOracleParameterSTATUS);

So on the whole we are setting 9 properties for a single parameter and if
this stored procedure accepts 10 parameters, then this process has to be
repeated for those many parameters.

Can any of the solution developers suggest me an alternative choice for
the
above code or how can I make this less expensive and efficient.

Thanks for your help!!!

Nov 19 '05 #6
Yes - use a code generator. There are code gen tools that you can
point to a database and they can spit out all the code you need for
the tables / sprocs / views. Here is one:
http://www.ericjsmith.net/codesmith/

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 13 May 2005 13:30:13 -0700, Diffident
<Di*******@discussions.microsoft.com> wrote:

Instead of coding these many lines for each and every parameter, is there
anyway that I can reduce the lines of code ? How can I design a resusable
method for setting these properties......so that this method can be called
for each and every parameter?

"Scott Allen" wrote:
Property getters and setters are generally short enough to be inlined
by the optimizing compiler, so they won't be as expensive as a method
call. No need to worry....

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 13 May 2005 12:41:11 -0700, Diffident
<Di*******@discussions.microsoft.com> wrote:
>Hello All,
>
>Best coding strategies for calling stored procedures from ASP.NET. As you
>are all aware that accessing a property is expensive than calling a method.
>For example in order to call a stored procedure which accepts 2 input
>parameters, we are currently following the below standard to set a single
>parameter:
>
>objOracleParameterSTATUS = new System.Data.OracleClient.OracleParameter ();
> objOracleParameterSTATUS.ParameterName ="STATUS_IN";
> objOracleParameterSTATUS.SourceColumn = "STATUS";
>objOracleParameterSTATUS.OracleType=System.Data.O racleClient.OracleType.Number;
> objOracleParameterSTATUS.Size =1;
> objOracleParameterSTATUS.Precision =0;
> objOracleParameterSTATUS.Scale =0;
>objOracleParameterSTATUS.Direction = System.Data.ParameterDirection.Input;
>objOracleParameterSTATUS.SourceVersion=System.Dat a.DataRowVersion.Current;
> objOracleParameterSTATUS.Value =STATUS;
> bjOracleCommand.Parameters.Add (objOracleParameterSTATUS);
>
>So on the whole we are setting 9 properties for a single parameter and if
>this stored procedure accepts 10 parameters, then this process has to be
>repeated for those many parameters.
>
>Can any of the solution developers suggest me an alternative choice for the
>above code or how can I make this less expensive and efficient.
>
>Thanks for your help!!!



Nov 19 '05 #7

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

Similar topics

11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
17
by: | last post by:
I have an app that retrieves data from an Access database. At the moment I have the SQL string as a Const in my app. I understand this is not best practice. I don't want the user to have access to...
8
by: Fredrik Melin | last post by:
I have a "Inventory" Object that contains the product and all its fields. The problem is that I am getting soooooo many functions under main Inventory class so it becames impossible to initalize...
10
by: Ren | last post by:
Hi All, I'm still rather new at vb.net and would like to know the proper way to access private varibables in a class. Do I access the variable directly or do I use the public property? ...
10
by: Jay Wolfe | last post by:
Hello, I'm trying to make sure I use best practices (and hence save myself some headaches) with the declaration and definition of global variables. Let's say I have an app with 30 files,...
4
by: Ned Balzer | last post by:
Hi all, I am pretty new to asp.net; I've done lots of classic asp, but am just beginning to get my mind wrapped around .net. What I'd like to do is include some code that tests if a user is...
2
by: MikeG | last post by:
When creating a class library is it wrong or not a 'Best Practice' to reference a property of an object from within a constructor or method of that object? I recall being told not to do this but I...
2
by: kbutterly | last post by:
All, I have a menu which contains Category as the master and Product as the child. When I click on a Category in the menu, I want one formView control, fvpc, to show, and then when I click on...
9
by: =?Utf-8?B?QW1tZXI=?= | last post by:
I've read many incomplete opinions about the "Best Practice" for securely accessing SQL but what I really need to find the "Best Practice" that fits my applications needs. Currently (alpha...
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
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:
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
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
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...
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.