Dima Protchenko wrote:
> Hi, guys.
> Please help if you know something about this.
>
> Error:
> ADODB.Recordset error '800a0e78'
> Operation is not allowed when the object is closed.
> line: if not rs.EOF then (from the code below)
>
> I have an SP on SQL2k that returns a recordset after a few data
> manipulations. The code for the SP is too long to attach here, but to
> describe it - it extracs some data from the db, stores it in the temp
> table (#), then does some data manipulation in that temp table and at
> the end of it I have:
>
> select * from #Courses
Nothing to do with your problem, but, you should avoid selstar (select *) in
production code. Don't force the query engine to resolve the * into a list
of columns every time the code runs.
> drop table #Courses
>
> which returns my recordset. On yeah - and I DO have SET NOCOUNT ON at
> the top of the SP
Darn! That was my first culprit!
>
> Now on the asp page I have this:
>
> dim conn, rs
> set conn = Server.CreateObject("ADODB.Connection")
> set rs = Server.CreateObject("ADODB.Recordset")
> conn.ConnectionString = "Provider=SQLOLEDB; server=**; Initial
> Catalog=SAGE; uid=**;pwd=**;"
> conn.Open
> rs.Open "exec dbo.usp_FindOneClass '15','2'", conn, adOpenDynamic, 1,
> 1
Why are you attempting to open an expensive dynamic cursor? An inexpensive
forward-only cursor would seem to suit your needs nicely.
While some folks here prefer to use this dynamic sql approach for executing
their stored procedures, I have some objections to it which you can read
about here:
http://tinyurl.com/jyy0
Do this instead:
'if you really think you need the dynamic cursor, add this line:
rs.CursorType = adOpenDynamic
'then:
rs.LockType = 1
conn.usp_FindOneClass '15','2', rs
I am a little curious as to why you are passing this numeric data as
strings. Are your parameters declared as numeric or char?
>
> if not rs.EOF then
> rs.MoveFirst
This MoveFirst line is completely unnecessary. The cursor will already be
pointing at the first record immediately after opening the recordset. Not
only is it unnecessary, in some circumstances it will cause your recordset
to be requeried, which is a complete waste of time.
> do while not rs.eof
> Response.Write(rs("CourseID"))
> rs.MoveNext
> loop
> end if
See here for alternatives to slow, inefficient recordset loops
http://www.aspfaq.com/show.asp?id=2467
HTH,
Bob Barrows
--
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"