Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 ADODB Not Returning Recordset

Author  Topic 

adweigert
Starting Member

22 Posts

Posted - 2003-09-17 : 14:55:23
I have a slight problem, a stored procedure isn't returning any results when called from within a VB COM object using ADODB. However, if I run the same SQL string in Query Analyzer the results are returned as expected.

The stored procedure is attrocious - the developer came from an informix background where cursors are common places - however it works - the code is too complex to simple re-write unfortunately but that's my next option if this can't be resolved by anyone. The code to call it is quite simple, infact since I didn't write this code originally - I inherited it - I thought perhaps there was a configuration issue so I created this VERY simple example to try and track down why the Recordset is being returned closed.

Dim objCmd As ADODB.Command
Dim objCn As ADODB.Connection
Dim objRs As ADODB.Recordset

Set objCn = New ADODB.Connection
Call objCn.Open("Provider=SQLOLEDB;Server=LOCALHOST;UID=stars;PWD=stars;Database=stars;")

Set objCmd = New ADODB.Command

With objCmd
.CommandText = "PROC_TransWorkflow"
.CommandType = adCmdStoredProc

Set .ActiveConnection = objCn
Call .Parameters.Refresh

.Parameters.Item("@select") = "wtt"
.Parameters.Item("@user") = "ADWeigert"
.Parameters.Item("@keyId") = 4
.Parameters.Item("@durationMinutes") = 0

Set objRs = .Execute()
End With

' Catch the Recordset not being open when it should be
Debug.Assert objRs.State = adStateOpen

If objRs.State <> adStateClosed Then
Call objRs.Close
End If

Set objRs = objCn.Execute("EXEC PROC_TransWorkflow " & _
"@durationMinutes=0," & _
"@user='ADWeigert'," & _
"@keyId=4, @select='wtt'")

' Catch the Recordset not being open when it should be
Debug.Assert objRs.State = adStateOpen

If objRs.State <> adStateClosed Then
Call objRs.Close
End If

If objCn.State <> adStateClosed Then
Call objCn.Close
End If

Set objCmd.ActiveConnection = Nothing

Set objCn = Nothing
Set objCmd = Nothing
Set objRs = Nothing

The second objCn.Execute string is the one that works when I run in Query Analyzer. Neither of these attempts work. I'm 100% sure that this is the parameter set that the application is trying to pass in - I debugged to the execution point to extract the parameters and compared them with the SQL Profiler parameters being passed.

My environment is: Windows XP Professional, Visual Basic 6 SP5, IIS 5 with COM+ 1.5.

I have tried using ADODB v2.1, 5, 6, and 7 with no luck. Any ideas? Sorry for posting this in this forum if it is not the correct one, I'm just desperate to resolve this.

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-09-17 : 15:15:08
did you try the setting the parameters without the @ symbol?

do you get an error message? that would be helpful !

- Jeff
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2003-09-17 : 15:16:15
Have you tried running profiler to see what is actually being executed?

I think you might need to turn on named Parameters. Like this

With objCmd
.NameParameters = true
End With


Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page

adweigert
Starting Member

22 Posts

Posted - 2003-09-17 : 15:25:36
quote:
Originally posted by jsmith8858

did you try the setting the parameters without the @ symbol?

do you get an error message? that would be helpful !


It didn't like the parameters without the @ symbol. This works fine in the same procedure with different parameter values.

Nope, no error messages, the Recordset is just closed.
Go to Top of Page

adweigert
Starting Member

22 Posts

Posted - 2003-09-17 : 15:27:00
quote:
Originally posted by MichaelP

Have you tried running profiler to see what is actually being executed?

I think you might need to turn on named Parameters. Like this

With objCmd
.NameParameters = true
End With



I did run profiler, I copied the SQL execution string straight from profiler and it worked fine.

NameParameters ? I remember something like that in ADODB but I haven't done this stuff in ages.
Go to Top of Page

adweigert
Starting Member

22 Posts

Posted - 2003-09-17 : 15:29:59
Good ole google gave me a hint to this ... http://www.codeguru.com/forum/showthread.php?threadid=261799

I tried your suggestions though with ADODB 2.7 but no luck, it still does not return a Recordset. :(
Go to Top of Page

LarsG
Constraint Violating Yak Guru

284 Posts

Posted - 2003-09-17 : 15:50:25
add

SET NOCOUNT ON

at the begining of the procedure
Go to Top of Page

adweigert
Starting Member

22 Posts

Posted - 2003-09-17 : 15:52:57
You've come across this then :) You are my hero, seriously ... I obviously didn't check the procedure enough to see that that wasn't turned on ...

Now on to the bigger problem... why would this work on a windows 2000 pro machine with ADODB 2.5 and not windows xp pro with ADODB 2.5 ? I believe I have also come across this problem on another windows 2000 pro machine ...
Go to Top of Page

simondeutsch
Aged Yak Warrior

547 Posts

Posted - 2003-09-17 : 22:38:43
Why would what work?
Does the app work only on a Win2K machine (I assume running SQL locally) and not on a WinXP Pro machine (I assume running SQL locally)? What exactly is the problem, the recordset not returning on a WinXP machine with the SET NOCOUNT ON/SET NOCOUNT OFF lines in the stored procedure?

Sarah Berger MCSD
Go to Top of Page

adweigert
Starting Member

22 Posts

Posted - 2003-09-18 : 08:13:05
Working environments:

Development machine:
Windows 2000 Professional SP3
ADODB 2.5
VB6 SP5
IIS 5
USING SQL Server 2000

Production:
Windows NT 4 SP6a
IIS 4
ADODB 2.5
USING SQL Server 7

Whenever I tried to put it on another workstation with Win2k or WinXp I was experiencing this issue. Sadly the programmer coded it as not to throw errors when data is not returned when it is required/expected... so it would just make the web application appear not to work fully.

The stored procedures ended up with half having the SET NOCOUNT ON statement and the other half did not. I added it to the half that didn't and all is well now.
Go to Top of Page
   

- Advertisement -