Re: Stored Procedures and RecordSets
- From: "Bob Barrows" <reb01501@xxxxxxxxxxxxxxx>
- Date: Sun, 11 Apr 2021 21:03:35 -0400
Stephen Howe wrote:
To date, all my Stored Procedures have been either actions (INSERT,
UPDATE or DELETE) or a single-row input/output of parameters. I am
mystified as to what needs to happen with regards to CursorLocation,
CursorType, LockType. Do I setup CursorLocation, CursorType,
LockType
in the Stored Procedure or does that happen with ADO's Command &
RecordSet object?
I do it with the ADO properties myself. Retrieving a recordset from
a stored
procedure is exactly the same as doing it with an ad hoc sql
statement.
Thanks. What I am mystified about is how the SP "knows" how to
communicate the recordset back.
If the Recordset was Server-sided, Forward-only, Read-only, then a
cursor has to be opened SQL Server.
How does the SP know that it needs to do this?
There is some aspect to this that I am missing.
The SP doesn't. It's the query engine that's running the queries in the
compiled procedure that is doing the work. And the query engine is
responding to the request received from ADO.
Speculation:
Ah, I wonder?
Perhaps the Recordset and/or ADO does what is necessary in terms of
opening and creating rowsets.
And then when the SP runs, it just fills what is there.
It is rather like a file handle and OPEN in VB. Perhaps the SP just
write records to whatever the "file handle" points to.
Close. I don't know the exact details - for those, you would need someone
like Bill Vaughn or David Sceppa. But it is something like that. ADO
requests the query engine to run the procedure and return the results with
the requested cursor type. Exactly how it does that depends on the provider
being used. The MSDASQL provider uses a different mechanism than the native
SQLOLEDB provider uses.
Of course, you do realize that the cursor and lock type you request might
not be the cursor and lock type you get.
See this thread: http://tinyurl.com/3cl6e
IMO, this is a bug in the SQLOLEDB provider. Interestingly enough, there is
a similar but different bug in the ODBC driver. When using ODBC with the
tests I performed in that thread, I get these results:
Before open, using stored procedure executed via dynamic sql, cursortype = 3
After open, using stored procedure executed via dynamic sql, cursor type =
3; RecordCount = -1
Before open, using stored procedure executed via
procedure-as-connection-method, cursortype = 3
After open, using stored procedure executed via
procedure-as-connection-method, cursor type = 3; RecordCount = -1
Before open, using stored procedure executed via Command object, cursortype
= 3
After open, using stored procedure executed via Command object, cursor type
= 3; RecordCount = -1
Before open, using dynamic sql, cursortype = 3
After open, using dynamic sql, cursor type = 3; RecordCount = 23
So, even though it's giving us the "right" cursortype, the recordcount is
not known. When I add this line:
"rsTest.Supports(adBookmark)=" & rsTest.Supports(adBookmark)
I discover that the only time bookmarks are supported is when using a
dynamic sql statement to open the recordset, rather than the stored
procedure.
This is not the documented behavior.
Workaround: use a client-side cursor (rs.cursorlocation=3) when opening the
recordset on a procedure, or use a more efficient method of getting the
record count.
Oh no, it's more than that. Those messages are sent as closed recordsets,
Just remember, if this is a SQL Server stored procedure, to have "SET
NOCOUNT ON" as the first line in your procedure, so you avoid the
extra
recordsets created by statements in your procedure that generate "x
rows
were affected by this query" messages.
Thank I know about "SET NOCOUNT ON".
Effectively it means the 2nd parameter of rthe Command Object is not
filled in on return.
and you cannot see the results of the intended recordset until those are
handled. Thus the need for NextRecordset in these cases.
--
Microsoft MVP - ASP/ASP.NET - 2004-2007
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: Stored Procedures and RecordSets
- From: Stephen Howe
- Re: Stored Procedures and RecordSets
- From: Bob Barrows
- Re: Stored Procedures and RecordSets
- References:
- Stored Procedures and RecordSets
- From: Stephen Howe
- Re: Stored Procedures and RecordSets
- From: Bob Barrows
- Re: Stored Procedures and RecordSets
- From: Stephen Howe
- Stored Procedures and RecordSets
- Prev by Date: Re: What's the steps to modify a .adp connect string & convert DAO to
- Next by Date: Re: Stored Procedures - Devils Advocate
- Previous by thread: Re: Stored Procedures and RecordSets
- Next by thread: Re: Stored Procedures and RecordSets
- Index(es):
Relevant Pages
|