Dan_Hero
Dan_Hero

Reputation: 55

Exporting database data to csv in classic asp

I've got a tbl_order table in my Microsoft SQL Server database, and I need to export some of the fields in a .csv file located in a folder which I have already granted write permission.

I wrote a code that I think it looks alright, but results in a timeout error even if the rows to export are at the moment just two.

I'd like to know where I'm wrong, since the script is super easy and I must be doing something very wrong.

Set objRS2 = Server.CreateObject("Scripting.FileSystemObject")
Set ctf = objRS2.CreateTextFile(Server.MapPath("../order/test.csv"), 2)
sql2 = "SELECT agent, dealer, data FROM tbl_order where active = 'True'"
objRS2.Open sql2, ConString
If Not objRS2.EOF Then
ctf.WriteLine("agent,dealer,data")
While Not objRS2.EOF   
ctf.WriteLine(""""&(rset1.Fields("agent").Value)&""" ,"""&(rset1.Fields("dealer").Value)&""","""&(rset1.Fields("data").Value)&"""")
objRS2.MoveNext
Wend
End If
ctf.Close
ClearRS(objRS2)

Upvotes: 0

Views: 1108

Answers (1)

Mike Poole
Mike Poole

Reputation: 2055

You are naming the filesystem object objRS2 and trying to use it as a database recordset. I would name it something like objFSO to make it clear it is a filesystem object and not a recordset.

You will need to create a recordset using a different name (e.g. rs). You can create the database recordset something like this before using it:

set rs = Server.CreateObject("ADODB.recordset")

Upvotes: 2

Related Questions