Optimize printing of great SQL-Server results through ASP

Asked

Viewed 269 times

0

Today I have a classic ASP page with an unconventional chain-select (read "armengado") that returns a select populated with some data from an sql-server database (2005).

I select the building and return the numbers of skillful floors for delivery in this building; simple.

It works very well today; The problem is that soon I will have to add more than 600 lines on this basis and the query will be very slow (since ASP needs to print all the data on the page before javascript picks up and takes to select.

I need to know if there’s a better way to search for this data - I can do an interaction SQL-SERVER -> JSON for data to come faster? Is there another way in ASP to popular the page faster? I need best practices in this particular example.

HTML

<div class="form-group">
    <label for="PREDIOS">PREDIOS</label>
    <%set RS = server.CreateObject ("ADODB.Recordset")
    RS.Open "select distinct PREDIOS from PI_AUTOCOMPLETAR_LOC ORDER BY PREDIOS",conn,1%>
    <select id="PREDIOS" name="PREDIOS" class="form-control" onchange="venha_lista();">
    <option value="">Selecione</option>
    <%If RS.bof And RS.eof Then
    response.write "Lista Vazia"
    Else
    While not RS.eof    
    Response.Write "<option value='"&RS("PREDIOS").value&"'>"&RS("PREDIOS").value&"</option>"
    RS.movenext
    Wend
    End If%>
     </select>
    </div>
<div id="ANDAR"></div>

Jquery

function venha_lista() {
    $.post("consulta_loc/atualizar_ANDAR.asp", $("#leva_servico").serialize(), function (data) {
        $("#ANDAR").html(data);
    });
};

update_ANDAR.Asp

<%set rs = server.CreateObject ("ADODB.Recordset")
PREDIO = REQUEST("PREDIO")
IF PREDIO = ""  THEN
PREDIO = "%"
end if
RS.Open "select distinct ANDAR from PI_AUTOCOMPLETAR_LOC WHERE PREDIO = '"&PREDIO&"' ORDER BY ANDAR",conn,1 %>
<select id="ANDAR" name="ANDAR" class="form-control">
<option value="">Selecione</option>
<% WHILE NOT RS.EOF %>
<option value="<%Response.write rs("ANDAR")%>"><%Response.write rs("ANDAR")%></option>
<% RS.MoveNext 
    WEND    %>
</select>
  • Instead of writing all the html code together with the necessary data, work with JSON objects. You will return very little data. There are today functions that you execute the query in this function and it already returns the Json object, example: QueryToJson(sql, conn). Jquery understands JSON which makes the job easier.

1 answer

1

One way out is to use the response.flush inside the loop.

"Seven" response.buffer=true at the beginning of your code. In the loop response.flush to write the content of the script every step of that loop...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.