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

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.CreateParameter();
prmCustAcctID.ParameterName = "@CustAcctID";
prmCustAcctID.SqlDbType = SqlDbType.NVarChar;
prmCustAcctID.Direction = ParameterDirection.Input;
prmCustAcctID.Size = 30;
prmCustAcctID.Value = strCustAcctID;
cmd.Parameters.Add(prmCustAcctID);

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 1819
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.CreateFactory("");
DBCommand cmd = db.GetStoredProcCommandWrapper("StoredProcName");
cmd.AddInParameter("InboundParam1", DbType.String, ParamValue);
cmd.AddOutParameter("OutParam1", DbType.Int32, 4);
cmd.AddOutParameter("OutParam2", DbType.Int32, 4);
db.ExecuteNonQuery(cmd);
cmd.GetParameterValue("OutParam1"); //get value of outbound param
cmd.GetParameterValue("OutParam2"); //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*********************@news.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.CreateParameter();
prmCustAcctID.ParameterName = "@CustAcctID";
prmCustAcctID.SqlDbType = SqlDbType.NVarChar;
prmCustAcctID.Direction = ParameterDirection.Input;
prmCustAcctID.Size = 30;
prmCustAcctID.Value = strCustAcctID;
cmd.Parameters.Add(prmCustAcctID);

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*********************@news.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.CreateParameter();
prmCustAcctID.ParameterName = "@CustAcctID";
prmCustAcctID.SqlDbType = SqlDbType.NVarChar;
prmCustAcctID.Direction = ParameterDirection.Input;
prmCustAcctID.Size = 30;
prmCustAcctID.Value = strCustAcctID;
cmd.Parameters.Add(prmCustAcctID);

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 ParameterDirection.Input is the default, for all your
inpur parameters you can reduce the number of lines of code by using:

cmd.Parameters.Add("@CustAcctID", SqlDbType.NVarChar, 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*********************@news.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.CreateParameter();
prmCustAcctID.ParameterName = "@CustAcctID";
prmCustAcctID.SqlDbType = SqlDbType.NVarChar;
prmCustAcctID.Direction = ParameterDirection.Input;
prmCustAcctID.Size = 30;
prmCustAcctID.Value = strCustAcctID;
cmd.Parameters.Add(prmCustAcctID);

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 ParameterDirection.Input is the default, for all your
inpur parameters you can reduce the number of lines of code by using:

cmd.Parameters.Add("@CustAcctID", SqlDbType.NVarChar, 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*********************@news.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.CreateParameter();
prmCustAcctID.ParameterName = "@CustAcctID";
prmCustAcctID.SqlDbType = SqlDbType.NVarChar;
prmCustAcctID.Direction = ParameterDirection.Input;
prmCustAcctID.Size = 30;
prmCustAcctID.Value = strCustAcctID;
cmd.Parameters.Add(prmCustAcctID);

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 SqlCommandBuilder 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.CreateParameter();
prmCustAcctID.ParameterName = "@CustAcctID";
prmCustAcctID.SqlDbType = SqlDbType.NVarChar;
prmCustAcctID.Direction = ParameterDirection.Input;
prmCustAcctID.Size = 30;
prmCustAcctID.Value = strCustAcctID;
cmd.Parameters.Add(prmCustAcctID);

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

4
by: Mike | last post by:
Hello, I'm currently working on debugging a very large DTS package that was created by someone else for the purpose of importing data into my company's database. The data is mainly...
15
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...
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...
1
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...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
2
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...
45
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
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...
2
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...
6
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...
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: 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
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,...
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
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...

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.