Avoiding a repeated request for MoveFirst

I have a request on an ASP page. After some conditions, the recordset that I have to print in three different tables. Therefore, in order to avoid the execution of almost one query 3 times, I decided to find a set of records for the results that I need ... therefore I need to do RS.MoveFirst two times. But ... when I parsed using SQL Profiler, I saw that the MoveFirst operation was repeatedly executing my query ... exactly what I wanted to avoid. How can I make a cache of results and only navigate through a set of records?

+3
source share
2 answers

Use Disabled Recordset

Const adOpenStatic = 3
Const adUseClient = 3
Const adLockOptimistic = 3

Dim conn: Set conn = Server.CreateObject("ADODB.Connection")
conn.Open sYourConnectionString

Dim rs : Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = adUseClient

rs.Open sYourSQL, conn, adOpenStatic, adLockOptimistic

Set rs.ActiveConnection = Nothing
conn.close

'' // You can now roam around the recordset with .MoveFirst, .MoveNext etc without 
'' // incurring any further hits on the DB.

, sql, ADODB.Command ( ). - , , .

+2

rs.getRows() ... , , , .

+1

Source: https://habr.com/ru/post/1714599/


All Articles