如何将大数据从MS SQL数据库导出到Classic ASP中的Excel文件

时间:2015-05-25 08:05:12

标签: asp-classic export-to-excel

我正在处理的一个Web应用程序是在 Classic ASP 中开发的。

现在我们将其移至 AZURE

,这是在本地服务器上

它没有 .NET Web应用程序那么强大。我面临的最常见的问题是导出报告数据。

将连接数据库中的数据导出为 Excel格式 CSV 的解决方案是什么?

选择查询包含超过50.000行,我不希望它崩溃

1 个答案:

答案 0 :(得分:0)

让我们开始:我将创建一个连接到简单表的简单示例。

<%@  language="VBScript" %> 
<%Response.Buffer = false%>  

<!--Time out for database connection-->
<% 
    Server.ScriptTimeout = 300
%>

<%
response.ContentType = "application/vnd.ms-excel"
response.AddHeader "content-disposition","attachment;filename=EnterFileName.xls"
response.CharSet = "UTF-8"


set Conn = server.CreateObject("ADODB.connection")
Conn.open Application("DBConnectionString") 
conn.CommandTimeout=1400 
set Rs = server.CreateObject("ADODB.recordset")
set RsSelect = server.CreateObject("ADODB.recordset") 

strQuery = "SELECT * FROM Countries "  
Rs.open strQuery, Conn, 1, 2
%>


<table>
    <tr>
        <td><strong>Name</strong></td>
        <td><strong>Code</strong></td> 
    </tr>
    <%
            do while not Rs.eof
    %>
    <tr> 
        <td><%=Rs("Name")%></td>
        <td><%=Rs("Code")%></td> 
    </tr>
                <% Rs.movenext    
                loop %>
</table>

<%
rs.Close
set rs = nothing
Conn.Close
Set conn = nothing
%>

如果您正确设置了时间,即使您的导出包含超过50.000行,每行都有多个列,您将获得导出并且不会崩溃。

相关问题