473,406 Members | 2,371 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,406 software developers and data experts.

Stored proc question

Hi all,

This may be slightly off-topic but it's from within asp.net I'm experiencing
this so here goes:

What is the most efficient way for me to call a SQL stored procedure
multiple times?

I know this may seem easy to some but it's got me good. I thought of
"preparing" the command object (since this is what it was meant for in the
previous ADO object model) but when I run the code, it complains about the
associated connection object being in an "open, fetching state". Please
don't suggest I should close/open the connection object because that just
seems to be defeating the whole command.prepare objective.

Any help here greatly appreciated.

Regards
John.
Nov 19 '05 #1
3 1059
Hi John:

The best optimization you could make is to avoid multiple round trips and
batch up the multiple calls into a single command (if you know how many times
you'll call the proc before starting). Delimit the command text with semicolons
for the SQL Server provider.

You can get multiple resultsets back with one trip. With a SqlDataAdapter
you'll have a DataTable for each resultset, with a SqlDataReader you'll need
to call NextResult().

Prepare won't help when sprocs are involved.

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/
Hi all,

This may be slightly off-topic but it's from within asp.net I'm
experiencing this so here goes:

What is the most efficient way for me to call a SQL stored procedure
multiple times?

I know this may seem easy to some but it's got me good. I thought of
"preparing" the command object (since this is what it was meant for in
the previous ADO object model) but when I run the code, it complains
about the associated connection object being in an "open, fetching
state". Please don't suggest I should close/open the connection object
because that just seems to be defeating the whole command.prepare
objective.

Any help here greatly appreciated.

Regards
John.

Nov 19 '05 #2

"John F" <a@b.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
Hi all,

This may be slightly off-topic but it's from within asp.net I'm
experiencing this so here goes:

What is the most efficient way for me to call a SQL stored procedure
multiple times?

I know this may seem easy to some but it's got me good. I thought of
"preparing" the command object (since this is what it was meant for in the
previous ADO object model) but when I run the code, it complains about the
associated connection object being in an "open, fetching state". Please
don't suggest I should close/open the connection object because that just
seems to be defeating the whole command.prepare objective.


SqlServer stored procedures cannot be prepared. In SqlServer a prepared
command only improves the text commands, not stored procedure invocations.
In fact preparing a command simply turns it into a stored procedure call!

So preparing won't help. Batching a number of stored procedure calls into
one big TSQL batch can improve things, but it can also degrade them, since
the command batch must be transmitted, parsed and compiled. You'll need to
test. Plus it's a hassle.

In general there's no very good way to invoke a command repeatedly in
ADO.NET/SQL Server, or to push large amounts of data to SQL Server.

David
Nov 19 '05 #3
Scott & Dave,

Thanks a lot to both of you guys. Not exactly what I was expecting (perhaps
I was just expecting some special keyword which did everything my 50 lines
of code is doing <joke>) but a definitive answer I can now deal with . . .

Regards
John.
"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:%2********************@tk2msftngp13.phx.gbl.. .

"John F" <a@b.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
Hi all,

This may be slightly off-topic but it's from within asp.net I'm
experiencing this so here goes:

What is the most efficient way for me to call a SQL stored procedure
multiple times?

I know this may seem easy to some but it's got me good. I thought of
"preparing" the command object (since this is what it was meant for in
the previous ADO object model) but when I run the code, it complains
about the associated connection object being in an "open, fetching
state". Please don't suggest I should close/open the connection object
because that just seems to be defeating the whole command.prepare
objective.


SqlServer stored procedures cannot be prepared. In SqlServer a prepared
command only improves the text commands, not stored procedure invocations.
In fact preparing a command simply turns it into a stored procedure call!

So preparing won't help. Batching a number of stored procedure calls into
one big TSQL batch can improve things, but it can also degrade them, since
the command batch must be transmitted, parsed and compiled. You'll need
to test. Plus it's a hassle.

In general there's no very good way to invoke a command repeatedly in
ADO.NET/SQL Server, or to push large amounts of data to SQL Server.

David

Nov 19 '05 #4

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

Similar topics

0
by: Dave Sisk | last post by:
I've created a system or external trigger on an AS/400 file a.k.a DB2 table. (Note this is an external trigger defined with the ADDPFTRG CL command, not a SQL trigger defined with the CREATE...
5
by: Rhino | last post by:
This question relates to DB2 Version 6 on OS/390. Can a (COBOL) stored procedure on this platform do file I/O, i.e. write to a sequential file? I am trying to debug a stored procedure. As far...
5
by: Andy G | last post by:
I have a registration page that captures 75% of the users data. After they enter that info they are redirected to one of two pages depending on how they answered a question on the registation...
14
by: Roy | last post by:
Apologies for the cross-post, but this truly is a two-sided question. Given the option of creating Looping statements within a stored proc of sql server or in the code-behind of an .net webpage,...
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
2
by: Roy | last post by:
Hey all, Here's a small VB codeblock that connects to a database and uses 2 SQL queries then forms a relation for a master/detail view on the aspx side: Private Sub Binddata(ByVal name As...
1
by: E.T. Grey | last post by:
I have been busting my nut over this for pretty much most of the day and it is driving me nuts. I posted this to an mySQL ng yesterday and I have not had any response (I'm pulling my hair out...
3
by: comp_databases_ms-sqlserver | last post by:
This post is related to SQL server 2000 and SQL Server 2005 all editions. Many of my stored procedures create temporary tables in the code. I want to find a way to find the query plan for these...
0
by: =?Utf-8?B?UXVpbWJseQ==?= | last post by:
At one seemingly inoccuous step in my CLR stored procedure, execution stops and the query times-out. I've tried debugging the stored proc by stepping into it from within VS. When I do, I get to...
0
by: mirandacascade | last post by:
Questions toward the bottom of the post. Situation is this: 1) Access 97 2) SQL Server 2000 3) The Access app: a) sets up pass-thru query b) .SQL property of querydef is a string, the...
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:
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
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
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
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...

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.