473,699 Members | 2,431 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 1831
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

4
6102
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 user/contact-related data for our customer base. We ran into problems when one import, of about 40,000 rows, took upwards of six hours to complete. Many of the stored procedures used by this package were written using XML. I've re-written many of them
15
6007
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
6698
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
2341
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
5451
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
2
2136
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
3398
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
2560
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
3012
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
7278
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
8687
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
8615
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,...
1
8914
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,...
1
6534
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
5874
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
4376
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
3057
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
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
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.