Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 Large SQL Export

Author  Topic 

badkneecap
Starting Member

10 Posts

Posted - 2008-03-30 : 17:55:11
I'm trying to export data from an SQL table using classic ASP. In the past, I have created tab delimited text files using code similar to the following code:

Response.AddHeader "Content-Disposition", "attachment;filename=results.txt"
Response.ContentType = "application/octet-stream"

Response.Write "Field1"&vbTAB
Response.Write "Field2"&vbTAB
Response.Write "Field3"&vbTAB
Response.Write vbCRLF

RSb.Open "SELECT * FROM tblData1 WHERE ID=1 ORDER BY txtField1", con, 3, 3
Do Until RSb.EOF
Response.Write RSb("txtField1")&vbTAB
Response.Write RSb("txtField2")&vbTAB
Response.Write RSb("txtField3")&vbTAB
Response.Write vbCRLF

RSb.MoveNext
Loop
RSb.Close

This always worked fine in the past because the tables were small. Now, the tables are exporting 100,000 records and getting errors. I'm setting the page timeout and the sql connection timeout, but I'm still getting errors. I'm not exactly sure what's happening, but the export stops after exporting about 5Mb. It varies where it stops, so I'm thinking it's timing out somewhere.

Is there a better way to do this? Possibly use an export function in MS SQL that would export faster?

TIA

- PR

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-03-30 : 18:01:14
What was the error? Tried with bcp?
Go to Top of Page

badkneecap
Starting Member

10 Posts

Posted - 2008-03-30 : 18:41:32
No error, download stops. Eventually, the page times out and generates a "Page cannot load" or something like that.

No, I have not tried bcp. What I like about doing it the way I am now is that the user selects the name and location of the file. Can I do this with bcp?

- PR
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-30 : 19:21:32
Yes. The BCP command accepts filenames.


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2008-03-31 : 01:38:53
Try it from within SQL Server via Query Analyzer.

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page
   

- Advertisement -