473,811 Members | 2,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling stored procedure with large number of parameters - performance concerns...

Hi...

I have a stored procedure that takes in a large number of parameters (around
30) and returns (as output parameters) another 10 or so.

At the moment, each parameter is declared, defined and added in my C# code
as follows:

SqlParameter prmCustAcctID = cmd.CreateParam eter();
prmCustAcctID.P arameterName = "@CustAcctI D";
prmCustAcctID.S qlDbType = SqlDbType.NVarC har;
prmCustAcctID.D irection = ParameterDirect ion.Input;
prmCustAcctID.S ize = 30;
prmCustAcctID.V alue = strCustAcctID;
cmd.Parameters. Add(prmCustAcct ID);

Multiply this by around 40, and you get a very long block of code!!!

Is there a better/faster/more improved way of doing something like this for
large numbers of parameters?

Thanks!
Alex
Dec 7 '05 #1
6 2567
Take a look at the Data Access block, included with the Enterprise Library.
http://www.gotdotnet.com/codegallery...2-91be63527327
Depending on the version (1.x or 2.x), it will vary, but the concept remains
the same

It reduces database calls to this pseudo code
Database db = Database.Create Factory("");
DBCommand cmd = db.GetStoredPro cCommandWrapper ("StoredProcNam e");
cmd.AddInParame ter("InboundPar am1", DbType.String, ParamValue);
cmd.AddOutParam eter("OutParam1 ", DbType.Int32, 4);
cmd.AddOutParam eter("OutParam2 ", DbType.Int32, 4);
db.ExecuteNonQu ery(cmd);
cmd.GetParamete rValue("OutPara m1"); //get value of outbound param
cmd.GetParamete rValue("OutPara m2"); //get value of outbound param

2 things I really like about it is
1. No need for @; the prefix is defined by the DB type in the setup
2. In theory, you can change the connection string to another DB type with
no changes to the data tier.

HTH,

Morgan
"Alex" <no****@hotmail .com> wrote in message
news:43******** *************@n ews.zen.co.uk.. .
Hi...

I have a stored procedure that takes in a large number of parameters
(around 30) and returns (as output parameters) another 10 or so.

At the moment, each parameter is declared, defined and added in my C# code
as follows:

SqlParameter prmCustAcctID = cmd.CreateParam eter();
prmCustAcctID.P arameterName = "@CustAcctI D";
prmCustAcctID.S qlDbType = SqlDbType.NVarC har;
prmCustAcctID.D irection = ParameterDirect ion.Input;
prmCustAcctID.S ize = 30;
prmCustAcctID.V alue = strCustAcctID;
cmd.Parameters. Add(prmCustAcct ID);

Multiply this by around 40, and you get a very long block of code!!!

Is there a better/faster/more improved way of doing something like this
for large numbers of parameters?

Thanks!
Alex

Dec 7 '05 #2
And to answer you question about performance... the # of parameters should
be a non-issue. The params are passed all at once when the command action is
called. I would be more concerned about what the proc's are doing once they
get the params.
"Alex" <no****@hotmail .com> wrote in message
news:43******** *************@n ews.zen.co.uk.. .
Hi...

I have a stored procedure that takes in a large number of parameters
(around 30) and returns (as output parameters) another 10 or so.

At the moment, each parameter is declared, defined and added in my C# code
as follows:

SqlParameter prmCustAcctID = cmd.CreateParam eter();
prmCustAcctID.P arameterName = "@CustAcctI D";
prmCustAcctID.S qlDbType = SqlDbType.NVarC har;
prmCustAcctID.D irection = ParameterDirect ion.Input;
prmCustAcctID.S ize = 30;
prmCustAcctID.V alue = strCustAcctID;
cmd.Parameters. Add(prmCustAcct ID);

Multiply this by around 40, and you get a very long block of code!!!

Is there a better/faster/more improved way of doing something like this
for large numbers of parameters?

Thanks!
Alex

Dec 7 '05 #3
Morgan,

Thanks for your quick response. The stored procedure itself is quite fast -
it just performs some validation on the parameters then uses them to insert
rows into a number of tables - this is much faster than calling multiple
inserts directly from C#, as some parameters are used more than once in the
various inserts (already did some performance testing on that which is why I
ended up with this scenario).

My main concern was finding the fastest way of building and passing the
parameters from C# to SQL... I'll have a look at the Data Access Block too,
thanks.

Regards,
Alexis
Dec 7 '05 #4
First of all, because ParameterDirect ion.Input is the default, for all your
inpur parameters you can reduce the number of lines of code by using:

cmd.Parameters. Add("@CustAcctI D", SqlDbType.NVarC har, 30).Value =
strCustAcctID;

Before you get hung up on a 'very long block of code!!!', have you
determined how long it takes to execute the resulting block of code. I think
you might be surprised at how little time it actually takes and that your
'problem' is a non-event.
"Alex" <no****@hotmail .com> wrote in message
news:43******** *************@n ews.zen.co.uk.. .
Hi...

I have a stored procedure that takes in a large number of parameters
(around 30) and returns (as output parameters) another 10 or so.

At the moment, each parameter is declared, defined and added in my C# code
as follows:

SqlParameter prmCustAcctID = cmd.CreateParam eter();
prmCustAcctID.P arameterName = "@CustAcctI D";
prmCustAcctID.S qlDbType = SqlDbType.NVarC har;
prmCustAcctID.D irection = ParameterDirect ion.Input;
prmCustAcctID.S ize = 30;
prmCustAcctID.V alue = strCustAcctID;
cmd.Parameters. Add(prmCustAcct ID);

Multiply this by around 40, and you get a very long block of code!!!

Is there a better/faster/more improved way of doing something like this
for large numbers of parameters?

Thanks!
Alex

Dec 7 '05 #5
If you don't want to handle parameter declaration code why not try
Microsoft Data Access Block.

Stephany Young wrote:
First of all, because ParameterDirect ion.Input is the default, for all your
inpur parameters you can reduce the number of lines of code by using:

cmd.Parameters. Add("@CustAcctI D", SqlDbType.NVarC har, 30).Value =
strCustAcctID;

Before you get hung up on a 'very long block of code!!!', have you
determined how long it takes to execute the resulting block of code. I think
you might be surprised at how little time it actually takes and that your
'problem' is a non-event.
"Alex" <no****@hotmail .com> wrote in message
news:43******** *************@n ews.zen.co.uk.. .
Hi...

I have a stored procedure that takes in a large number of parameters
(around 30) and returns (as output parameters) another 10 or so.

At the moment, each parameter is declared, defined and added in my C# code
as follows:

SqlParameter prmCustAcctID = cmd.CreateParam eter();
prmCustAcctID.P arameterName = "@CustAcctI D";
prmCustAcctID.S qlDbType = SqlDbType.NVarC har;
prmCustAcctID.D irection = ParameterDirect ion.Input;
prmCustAcctID.S ize = 30;
prmCustAcctID.V alue = strCustAcctID;
cmd.Parameters. Add(prmCustAcct ID);

Multiply this by around 40, and you get a very long block of code!!!

Is there a better/faster/more improved way of doing something like this
for large numbers of parameters?

Thanks!
Alex


Dec 7 '05 #6
You may want to look at the SqlCommandBuild er class. This will allow
you to populate the parameters from the sql stored procedure. It will
cause actual execution time to be slower (cause it has to round-trip the
server to get the information) (although probably not noticably) but
will reduce the amount of code you have to write.

John


Alex wrote:
Hi...

I have a stored procedure that takes in a large number of parameters (around
30) and returns (as output parameters) another 10 or so.

At the moment, each parameter is declared, defined and added in my C# code
as follows:

SqlParameter prmCustAcctID = cmd.CreateParam eter();
prmCustAcctID.P arameterName = "@CustAcctI D";
prmCustAcctID.S qlDbType = SqlDbType.NVarC har;
prmCustAcctID.D irection = ParameterDirect ion.Input;
prmCustAcctID.S ize = 30;
prmCustAcctID.V alue = strCustAcctID;
cmd.Parameters. Add(prmCustAcct ID);

Multiply this by around 40, and you get a very long block of code!!!

Is there a better/faster/more improved way of doing something like this for
large numbers of parameters?

Thanks!
Alex

Dec 7 '05 #7

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

Similar topics

15
6019
by: Jarrod Morrison | last post by:
Hi All Im generally a vb programmer and am used to referencing multiple records returned from a query performed on an sql database and im trying to move some functions of my software into sql stored procedures. So far ive been able to move the functions relatively easily but im unsure about how to output multiple values from an sql stored procedure. By this i mean for example one of the stored procedures may take your username and return...
0
6707
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...
1
2348
by: Rhino | last post by:
I am trying to get a sense of requirements and best practices for Java stored procedures in DB2 V7.2 for Windows. 1. Is it required or recommended that any of the following be closed before leaving the stored procedure: open Statement and PreparedStatement objects; open ResultSet objects; open JDBC connections? Although the stored procedure will still run succesfully if these open objects and connections are not closed, are there any...
2
5464
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
2
2143
by: Woody Splawn | last post by:
I am using SQL Server 2000 as the back-end. I have created a stored procedure in SQL server called usp_AddContract. This Stored procedure inserts a new contract into a contracts table. I have tested the code in Enterprise Manager and it works correctly. At the time that I run the SP I pass a contract number and a SSN to the SP and it creates a new contract in the contracts table with a unique value in the ConNum field and SSN field. In...
45
3421
by: John | last post by:
Hi When developing vb.bet winform apps bound to sql server datasource, is it preferable to use SELECTs or stored procedure to read and write data from/to SQL Server? Why? Thanks Regards
6
1836
by: Alex | last post by:
Hi... I have a stored procedure that takes in a large number of parameters (around 30) and returns (as output parameters) another 10 or so. At the moment, each parameter is declared, defined and added in my C# code as follows: SqlParameter prmCustAcctID = cmd.CreateParameter(); prmCustAcctID.ParameterName = "@CustAcctID";
2
3018
by: E11esar | last post by:
Hello there. I am going in bit of a circle with this matter; First some background: I am trying to upload the details of a CSV file into an Oracle table. I am using a StreamReader to copy a line at a time into an array, using a string columns = line.Split(separators.ToCharArray()); command. Here is a definition of the table I am loading into:
6
7291
Soniad
by: Soniad | last post by:
Hello, I am excecuting a stored procedure in my ASP page , it has one out parameter (@confirm) . after executing the procedure i want to retreive this out parameter and assign it to variable (confirmation) declared in page. Dim RsSp , SQLSp Set RsSp = Server.CreateObject("ADODB.Recordset") SQLSp = "Declare @confirm varchar(1)" SQLSp = SQLSp & "Exec SendMsg_proc "& "'" & UniCode &"' , '" & DintUserId &"' , '" & DintOrg_id &"' ,...
0
9728
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
10648
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
10389
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
10402
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
10135
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
9205
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...
1
7670
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4339
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

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.