FIX: Getting SELECT DISTINCT to Work Under ADO with SQL Server (181479)
The information in this article applies to:
- ActiveX Data Objects (ADO) 1.0
- ActiveX Data Objects (ADO) 1.5
- ActiveX Data Objects (ADO) 2.0
- ActiveX Data Objects (ADO) 2.1
- ActiveX Data Objects (ADO) 2.5
- ActiveX Data Objects (ADO) 2.6
- Microsoft SQL Server 6.5
- Microsoft SQL Server 6.5 Service Pack 1
- Microsoft SQL Server 6.5 Service Pack 2
- Microsoft SQL Server 6.5 Service Pack 3
- Microsoft SQL Server 6.5 Service Pack 4
This article was previously published under Q181479 SYMPTOMS
Under certain conditions with ActiveX Data Objects (ADO), SELECT DISTINCT
in your SQL statement will not provide distinct records.
Any of the following situations produces incorrect results with SQL
Server:
- You open a recordset with rs.open "select ....." with no command
object.
- You open a recordset with the rs.open command.
- You open a recordset with Set rs= command.execute and the
cursorlocation was set to rduseclient.
This happens either when you use the Recordset.Open method or when the
recordset is obtained from a command object by setting the recordset equal
to the return value of Command.Execute.
CAUSE
The reason this does not work with adUseClient is that ADO uses SQL
Server's FOR BROWSE option on the SQL statement to get extended metadata in
order to process updates. The use of this option causes SQL version 6.5 to
ignore the DISTINCT keyword.
RESOLUTION
Here are the two possible techniques you can use to get SELECT DISTINCT to work as expected:
- Set the CursorLocation to adUseServer instead of adUseClient.
- When using the Open method with adUseClient you can work around this
problem by using a command object and setting its ActiveConnection to
the connection used in the Open statement.
The "Steps to Reproduce Behavior" section demonstrates the workarounds for both the Open and the Command methods.
STATUS
This problem is fixed with the release of Service Pack 5 for SQL Server 6.5 and SQL Server 7.x.
Modification Type: | Minor | Last Reviewed: | 3/14/2005 |
---|
Keywords: | kbADO210sp2fix kbbug kbDatabase kbfix kbSQLProg KB181479 |
---|
|