Use the simplest steps to back up SQL database files to the local machine:
Response. Charset = "UTF-8"
Session. Codepage = 65001
Response. Buffer = true
Response. Clear
'Change the user name and password based on your situation
Constr = "Provider = SQLOLEDB.1; Persist Security Info = True; User ID = endiva; Password = endiva; Data Source = 211.160.78.6"
Set conn = server. createobject ("adodb. connection ")
Conn. open constr
Bkfname = server. mappath (Format_Time (Now (), 5) & "database. bak ")
Sqlstr = "backup database fang to disk = '" + bkfname + "' with init"
Conn.exe cute sqlstr
Conn. close
Response. Write "database [fang] is backup success! "
Response. Write "click download"
If you want to back up and download the data directly, you can add the following part to save the backup automatically. However, the pop-up file is a. asp file. Modify the file and click OK.
'Set fn = server. createobject ("adodb. stream ")
'Fn. mode = 3' read/write
'Fn. type = 1' data type: adTypeBinary
'Fn. open
'Fn. LoadFromFile bkfname': mount the file specified by bkfname to the object
'Response. ContentType = "application/octet-stream"
'Response. BinaryWrite fn. read
'Fn. close