Computing.Net > Forums > Programming > Stored Procedure not working if OLE

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Stored Procedure not working if OLE

Reply to Message Icon

Name: tfs
Date: April 4, 2004 at 22:43:00 Pacific
OS: W2k
CPU/Ram: 800Mhz Pentium
Comment:

I have a stored procedure that will not work, if I have an update in it. I assume this has something to do with a readonly access. I am running SQL Server 6.5 and I can run it fine from the query program, so the problem is not with Sql Server, but from the recordset access.

Actually, I don't know why I am having the problem, but if it seems to fail when I am doing an OLE connection, but works fine when I do an ODBC connection.

Someone said that the problem was that you couldn't do an update and a select in the same SP. That didn't make any sense. How would ADO know what is happening inside of the Stored Procedure? This is done on the Server and only the results would be sent back.

Also, why would it work with ODBC and not OLE?

The stored procedure is -

*******************************************

CREATE PROCEDURE getLastBook as

declare @book char(5)

select @book=max(book_key) from booking

update booking set status = 25 where book_key = "70005"

select @book

********************************************

This is passing back the variable @book as well as the update.


******************************************

<HTML>

<HEAD>

<TITLE>ABC Corporation</TITLE>

</HEAD>

<BODY>

<H2>ABC Corporation Employee Telephone Extensions</H2>

<%

Dim connectionToDatabase

Dim recordCollection

Set connectionToDatabase=Server.CreateObject("ADODB.Connection")

'connectionToDatabase.Open "Driver=SQL Server; Server=steg; uid=sa; pwd="

connectionToDatabase.Open "Provider=sqloledb;data source=steg;" & _

"initial catalog=travdata;" & _

"user id=sa;password="

Set recordCollection =connectionToDatabase.Execute("exec getLastBook")

if not recordCollection.eof then

response.write(recordCollection(0))

end if

connectionToDatabase.Close

Set connectionToDatabase=Nothing

%>

</BODY>

</HTML>

*****************************************

You will notice 2 connection open calls. In this case, I have the ODBC one commented out and get the following error:


*****************************************

Error Type:

ADODB.Recordset (0x800A0E78)

Operation is not allowed when the object is closed.

/connectDB13.asp, line 22


********************************************

If I comment out the 2nd one (the OLE connection) and uncomment the ODBC open, it works fine and passes back the book number. The page returned is:

******************************************

ABC Corporation Employee Telephone Extensions

70094

*****************************************

This is what I would expect - Why doesn't the OLE connection work - it does do the update, BTW, even though it doesn't pass back the booking (or at least the recordset is not opened - as the .execute is supposed to do and does in the ODBC type).



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Stored Procedure not working if OLE

Stored Procedure with update not wo www.computing.net/answers/programming/stored-procedure-with-update-not-wo/10001.html

Store Procedure in Sql ..? www.computing.net/answers/programming/store-procedure-in-sql-/9409.html

this should NOT work, but ... www.computing.net/answers/programming/this-should-not-work-but-/13970.html