ASP obtains binary data of the MSSQL database

Source: Internet
Author: User
1. Save it to the server

<%

Dim id_srl 'request. querystring ("id_srl ")

Id_srl = 49

If CINT (id_srl)> 0 then

Dim Conn, connstr, RS, SQL, mystream

Connstr = "provider = sqloledb.1; persist Security info = false; user id = fdp_user; initial catalog = FDP; Data Source = 10.120.120.153; locale identifier = 1036; Connect timeout = 15; use procedure for prepare = 1; Auto translate = true; packet size = 4096 ;"

Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open connstr, "fdp_user", "rlxhamster"

SQL = "select * From srl_contenu where id_srl =" & id_srl

Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open SQL, Conn, 1, 3

Set objstream = server. Createobject ("ADODB. Stream ")

Objstream. type = 1
Objstream. Open
Objstream. Write RS ("contenu"). getchunk (RS ("contenu"). ActualSize-78)
Objstream. savetofile server. mappath ("DB") & "\" & RS ("nom_fichier"), 2

Set FSO = server. Createobject ("scripting. FileSystemObject ")
If FSO. fileexists (server. mappath ("DB") & "\" & RS ("nom_fichier") = true then
Response. Write "file" & RS ("nom_fichier") & "saved success !! "
End if

Objstream. Close
Set objstream = nothing

Rs. Close
Set rs = nothing

Conn. Close
Set conn = nothing

End if

%>

 

2. File Download example

<%

'Set the file size and Mime Type
Function setfordisplay (field, contenttype)
Contenttype = lcase (TRIM (contenttype ))
Nfieldsize = field. actualsize
Bytes = field. getchunk (nfieldsize)
Session ("bytes") = bytes
Session ("type") = contenttype
End Function

Function setfilesize (field)
Nfieldsize = field. actualsize
Setfilesize = field. getchunk (nfieldsize)
End Function

Setfordisplay RS ("contenu"), RS ("content_type ")
Response. addheader "content-disposition", "attachment; filename =" & RS ("nom_fichier ")
Response. contenttype = SESSION ("type ")
Response. binarywrite SESSION ("bytes ")
Session ("type") = ""
Session ("bytes") = ""

%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.