No data is returned in Visual FoxPro when you use the TOP clause to retrieve data from a table in SQL Server 7.0 or in SQL Server 2000 (260526)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 3.0
  • Microsoft Visual FoxPro for Windows 3.0b
  • Microsoft Visual FoxPro for Windows 5.0
  • Microsoft Visual FoxPro for Windows 5.0a
  • Microsoft Visual FoxPro for Windows 6.0
  • Microsoft Visual FoxPro for Windows 7.0
  • Microsoft Visual FoxPro 8.0
  • Microsoft Visual FoxPro 9.0 Professional Edition

This article was previously published under Q260526

SYMPTOMS

When using the TOP clause in a SELECT-SQL statement that is retrieving data from a table in a SQL Server 7.0 or SQL Server 2000 database, no data is returned to Visual FoxPro.

CAUSE

The TOP clause is new to SQL Server 7.0 and SQL Server 2000. The reason that no data is being returned is that the compatibility mode on the database from which the data is being retrieved is set to 6.5.

RESOLUTION

Change the compatibility mode of the database to 7.0 or 8.0 (for SQL Server 2000). This allows the correct data to be returned. The different modes for SP_DBCMPTLEVEL are 60, 65, 70, 80; see SP_DBCMPTLEVEL in SQL Server Books Online for more information.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

The compatibility of a SQL Server 7.0 or SQL Server 2000 database can be changed by using the SP_DBCMPTLEVEL command. For example, you can issue the command SP_DBCMPTLEVEL pubs, 70 in the SQL Server 7.0 Query Analyzer window, or send it through the Visual FoxPro ODBC driver using the SQLEXEC command.

Create a program (.prg) file and run the following code, changing the database name to your database wherever necessary:
*!* Make changes to the connect string, adding your server, database,
*!*      login, and password.
MyConnect_Str = 'DRIVER={SQL Server}; SERVER=YourServer;' + ;
                'DATABASE=YourDatabase;UID=sa;PWD='
*!* Connects to SQL Server using the connect string.
MyHandle = SQLSTRINGCONN(MyConnect_Str)
IF MyHandle > 0
*!* Comment out the next line and uncomment the line after to return data.
    Change_Ver = SQLEXEC(MyHandle, "SP_DBCMPTLEVEL pubs, 65") &&Returns Error
*!* Change_Ver = SQLEXEC(MyHandle, "SP_DBCMPTLEVEL pubs, 70") &&Returns Top 5
   MyExec = SQLEXEC(MyHandle, "SELECT  TOP 5 * FROM authors")
      IF MyExec < 1
         WAIT WINDOW "SELECT statement failed!"
      ELSE
         BROWSE
         USE	
      ENDIF
ELSE
      WAIT WINDOW "Connection failed!"
ENDIF 
				

REFERENCES

For additional information on determining SQL Server Compatibility Levels, click the article number below to view the article in the Microsoft Knowledge Base:

233508 HOWTO: Determine Compatibility Level of a SQL Server 7 Database


Modification Type:MajorLast Reviewed:3/17/2005
Keywords:kbCodeSnippet kbprb kbSQLProg KB260526