Re: Command object and batching stored procedure calls
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Tue, 19 Feb 2008 21:48:47 -0500
Michael Viking wrote:
I'm using SQL Server. For example, the books online do not list a
semi-colon as a delimiter in the help for the 'CommandText' property
of the ADO Command object. For example here:
http://msdn2.microsoft.com/en-us/library/ms675958(VS.85).aspx. What
should I be reading if not that?
First off, you are reading the ADO documentation: you should be reading the
SQL Server documentation.
As is said on the page you cited, the string assigned to the CommandText
property should be "any other type of command statement recognized by the
provider", i.e., a properly formatted statement that will be properly parsed
and executed by the target database. In SQL Server, a semicolon is the
standard statement delimiter. If you are using SQL 2005, and you have
installed BOL, see this
page:ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/84a1510d-7cbe-4bd1-a328-b873ee1bbe5f.htm.
If you were using a different database, the delimiter might be different.
Some databases, such as Jet (Access), don't support batched statements at
all.
22 separate statements is the most I've been able to get in one
CommandText, but I've seen as few as 15 be the maximum. It doesn't
seem to be related exactly to the length of CommandText, either,
because I've tried cutting them off by string length. As I've said,
it appears to be magic formula. I'd appreciate it if you could point
me to the Books Online where it's documented how many can be sent via
a Command object, or what the maximum length is or something.
I've never looked because it's nothing I have ever considered doing.
However, on this page
(ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/instsql9/html/13e95046-0e76-4604-b561-d1a74dd824d7.htm),
you can see that the maximum batch size is "65,536 * Network Packet Size".
It does not sound from your description that you are getting anywhere near
this limit. What error are you getting that makes you think you've exceeded
a limit?
See below about telling ADO that you are not expecting records to be
returned by your batch's execution. Maybe that is related to your symptom.
Perhaps ADO isn't the best tool...If I need to run a stored procedure
on the DB every time a line of data comes in over a port, what do you
recommend? Naively it's safe and easy to use a command object and
execute the stored procedure every time a line comes in. Easy to
understand, program and it's safe. Performance: dismal.
One way to improve performance using the Command object is to specify
adExecuteNoRecords in the <options> argument when calling the Execute
method. If you do not specify that, ADO, by default, creates a recordset
object behind the scenes to receive any resultsets returned from the
execution. You need to tell ADO that you are not getting any records back.
ObviousThis is not a situation I've ever encountered; however ...
answer: queue them up somehow and batch process them. I'm posting to
get ideas...What's the best tool?
You might consider writing the data to a csv file, which can be periodically
imported into SQL via bcp, DTS or SSIS (... what version of SQL are you
using?), then a T-SQL process can loop through the data, using it to run the
stored procedure.
Another option is to go to a level below ADO and use OLE DB directly. See
http://msdn2.microsoft.com/en-us/library/ms722784(VS.85).aspx
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
.
- Follow-Ups:
- Re: Command object and batching stored procedure calls
- From: Michael Viking
- Re: Command object and batching stored procedure calls
- References:
- Command object and batching stored procedure calls
- From: Michael Viking
- Re: Command object and batching stored procedure calls
- From: Bob Barrows [MVP]
- Re: Command object and batching stored procedure calls
- From: Michael Viking
- Re: Command object and batching stored procedure calls
- From: Bob Barrows [MVP]
- Re: Command object and batching stored procedure calls
- From: Michael Viking
- Command object and batching stored procedure calls
- Prev by Date: Re: Command object and batching stored procedure calls
- Next by Date: Re: Command object and batching stored procedure calls
- Previous by thread: Re: Command object and batching stored procedure calls
- Next by thread: Re: Command object and batching stored procedure calls
- Index(es):
Relevant Pages
|