用最簡單的步驟備份sql數據庫的文件到本地:
response.Charset = "utf-8"
Session.Codepage = 65001
Response.Buffer=true
Response.Clear
'根據你的情況修改用戶名和密碼
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.execute sqlstr
conn.close
response.Write "database [fang] is backup success! "
response.Write "click download"
如果想直接備份並下載,可以加上下邊的這部分,就會備份後自動保存。但是彈出的文件是.asp的文件,修改下就OK。
'set fn=server.createobject("adodb.stream")
'fn.mode=3 '讀寫
'fn.type=1 '數據類型為:adTypeBinary
'fn.open
'fn.LoadFromFile bkfname '將bkfname指定的文件裝入對像中
'Response.ContentType="application/octet-stream"
'Response.BinaryWrite fn.read
'fn.close