Different query results!

I have a query which returns one set of results when run in SQL Query Analyzer, but only a subset of those results when executed within our application using ADO (not ADO.NET). Obviously this is very strange behaviour, and we would like all our query results to be available in our application.

Would appreciate any assistance.

Cheers,
Fidel
[363 byte] By [Comrade Fidel] at [2007-11-19 11:01:48]
# 1 Re: Different query results!
Please post the code and the query...Really hard to understand the reasons without some code.
What cursor type do you use ?
hspc at 2007-11-9 13:41:55 >
# 2 Re: Different query results!
It really depends upon the sql command you are sending to the server.

I would recommend you to debug the application and check the value of the sql command build and execute it in query analyzer to see whther the resultant is same or not...

good luck
Andy Tacker at 2007-11-9 13:42:56 >
# 3 Re: Different query results!
Please post the code and the query...Really hard to understand the reasons without some code.
What cursor type do you use ?

Hi hspc, thanks for your response. We're using a static cursor to obtain a read-only recordset.

The code which queries the DB is in a VB6 COM+ object, and looks like this:

Public Function RunSQLReturnRS(ByVal QueryString As String, Optional ByVal Params As Variant, Optional ByVal ConnectionStringValue As String) As ADODB.Recordset

' Declare variables
Dim conConnection As ADODB.Connection
Dim rstRecordset As ADODB.Recordset
Dim cmdCommand As ADODB.Command

' Create objects
Set conConnection = New ADODB.Connection
Set rstRecordset = New ADODB.Recordset
Set cmdCommand = New ADODB.Command

' Init the ADO objects & the stored proc parameters
If ConnectionStringValue = "" Then

conConnection.ConnectionString = mstrConnectionString

Else

conConnection.ConnectionString = ConnectionStringValue

End If

conConnection.Open

With cmdCommand
Set .ActiveConnection = conConnection
.CommandText = QueryString
.CommandType = adCmdText
End With

CollectParams cmdCommand, Params
rstRecordset.CursorLocation = adUseClient

' Execute the query for readonly
rstRecordset.Open cmdCommand, , adOpenStatic, adLockReadOnly

' Disconnect the recordsets and cleanup
Set rstRecordset.ActiveConnection = Nothing
Set cmdCommand.ActiveConnection = Nothing
Set cmdCommand = Nothing
conConnection.Close
Set conConnection = Nothing

' Return the resultant recordset
Set RunSQLReturnRS = rstRecordset

End Function

To execute our query, we call the object from a VBScript ASP page like this:

Set mrstRecordset = mobjDBHelper.RunSQLReturnRS(mstrSQL, Null, Session("ConnectionString"))

The query itself looks like this:

SELECT c.call_id, c.calldate, e.employee_name, co.description,
ca.campaign_name, s.name AS script_name, c.campaign_id, c.script_id,
c.customer_id, c.number_dialled
FROM calls AS c INNER JOIN eControl.dbo.employees AS e
ON c.employee_id = e.employee_id
INNER JOIN calloutcome AS co ON c.calloutcome_id = co.calloutcome_id
LEFT OUTER JOIN campaign AS ca ON ca.campaign_id = c.campaign_id
LEFT OUTER JOIN script AS s ON s.script_id = c.script_id
WHERE c.customer_id = 123456
ORDER BY calldate DESC ;

Hope this is the information you requested.

Regards,
Fidel
Comrade Fidel at 2007-11-9 13:43:58 >
# 4 Re: Different query results!
in some cases RecordCount property returns -1
because of using unsupported CursorType...
is this the case ?
also are you sure that you test using the same parameters in the where clause ?
hspc at 2007-11-9 13:44:56 >
# 5 Re: Different query results!
[ Merged threads ]
Andreas Masur at 2007-11-9 13:45:54 >
# 6 Re: Different query results!
what is the strange result u got from that query? or is it possible that ur connection string point to different database?
erickwidya at 2007-11-9 13:46:54 >