Solved

RDO and Stored Procedures (SQL Server)

Posted on 1997-11-27
5
309 Views
Last Modified: 2011-04-14
<NT4, VB5, SQL-Server 6.5>
Hi everybody!
I have a problem using RDO and stored procedures.
From VB5 I execute this piece of code to retrieve a resultset. I have one in-parameter.

------------------------------------------------------------
Set rsRes = rdCon.OpenResultset("exec spTest 'DEM',
                     rdOpenDynamic,rdConcurReadOnly)
------------------------------------------------------------

The stored procedure "spTest" looks like this:
------------------------------------------------------------
CREATE PROCEDURE spTest
@isokod char (3)
AS
IF @isokod='ALL'
  BEGIN
    select isokod, afnr, sub
    from tblSebtrade
    order by isokod
  END
ELSE
  BEGIN
    select isokod, afnr, sub
    from tblSebtrade
    where isokod=@isokod
    order by isokod
  END
GO
------------------------------------------------------------

And the errormessage :) is:
------------------------------------------------------------
Run-time error '40002':
37000:[Microsoft][ODBC SQL Server Driver][SQL Server]
Cannot open a cursor on a stored procedure that has
anything other than a single select statment in it.
------------------------------------------------------------

I understand the errormessage allright but I have done things like this before (not using RDO). What am I doing wrong this time?
I suspect that I can write the SP in a different way in
order to achieve what I want, but I don't know how...
I would really appreciate help!

                     Best regards // Anders Karlsson
0
Comment
Question by:Kalle 2
  • 3
  • 2
5 Comments
 

Author Comment

by:Kalle 2
ID: 1442690
Edited text of question
0
 
LVL 12

Expert Comment

by:Trygve
ID: 1442691
I might be way of base here, but couldn't you just provide a SQL-statement instead of running it as a stored procedure ?

Something like this

Myisokod="DEM" ' or whatever

SqlStatement="select isokod, afnr, sub from tblSebtrade where '" & MyIsokod & "' = 'ALL' OR isokod='" & MyIsokod & "' order by isokod "

Set rsRes = rdCon.OpenResultset(SqlStatement, rdOpenDynamic,rdConcurReadOnly)


Trygve
0
 

Author Comment

by:Kalle 2
ID: 1442692
Yes I could do that but I dont want to! :)
I have other, more complex, procedures I want to execute
and they all use this technique. I should work and I
cant seem to find the problem.

0
 
LVL 12

Accepted Solution

by:
Trygve earned 150 total points
ID: 1442693
It seems to me that you are using a cursor on your connection.

Try using a cursorless result set;   rdCon.CursorDriver = rdUseNone


Another solution could be to let the stored procedure produce a temporary table on the server use another openresultset to get the data and then delete the temp table.
0
 

Author Comment

by:Kalle 2
ID: 1442694
I changed the cursortype as you mentioned and it worked
just fine.
This solved my problem and got me going again, thanks!

                                        // Anders Karlsson
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now