I have a legacy web-site that I am maintaining (built mostly in classic ASP with vbscript). I am making some modifications to it, and got tired of waiting 5 minutes everytime I had to go through one of the pages that was loading 99000 records from the database before displaying the first 20 of them, so I rewrote the code as:
sSQL = "WITH OrderedAgreements AS (SELECT *, ROW_NUMBER() OVER (ORDER BY " & strSort & ") AS 'RowNumber' FROM ServiceAgreement " & WhereClause & ")"
sSQL = sSQL & " SELECT * FROM OrderedAgreements WHERE RowNumber BETWEEN " & iStartRec & " AND " & iStartRec + iPageSize - 1
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sSQL, SQLConn, adOpenStatic, adLockReadOnly
(the objective being to return only the rows that will actually be displayed).
This runs fine when run from IIS-7 on my local development machine (Windows 7). It is accessing a test database under SQL Server 2008 on a development server in an adjacent lab.
However, when I run the identical code in a beta site on the production server (i.e., a parallel directory tree to the production site, accessed through a different HTTP port), it gives me a "syntax error near keyword 'WITH'"
The production server is running Windows Server 2003 R2 and IIS 6, but I can't think of a reason why that should cause an error on one machine and not on the other. They are running identical code, connecting to the same database, accessed with the same sequence of command. I even put some logging code in to output the SQL that is being generated, and it is identical in both cases. Both machines are running the 2.0/3.0/3.5 framework. Both machines have SQL Server 2008 installed.
The production server is accessible to me (via RDP), but it does not have Visual Studio on it. I am pretty much at my wits end as to figuring out why the same code is getting an SQL syntax error on one machine and not the other.
Can anyone give me a clue as to how to proceed? Thanks.