Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > asp入门教程

asp在线备份与恢复sqlserver数据库的代码

来源:中文源码网    浏览:277 次    日期:2024-05-12 04:03:24
【下载文档:  asp在线备份与恢复sqlserver数据库的代码.txt 】


asp 在线备份与恢复sqlserver数据库的代码
asp在线备份sql server数据库: 1、备份sqlserver 复制代码 代码如下: <% SQL="backup database 数据库名 to disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"'" set cnn=Server.createobject("adodb.connection") cnn.open "driver={SQL Server};Server=服务器名;uid=sa;pwd=" cnn.execute SQL on error resume next if err<>0 then response.wrITe "错误:"&err.Descripting else response.wrITe "数据备份成功!" end if %> 2、恢复sqlserver 复制代码 代码如下: <% SQL="Restore database 数据库名 from disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"'" set cnn=Server.createobject("adodb.connection") cnn.open "driver={SQL Server};Server=服务器名;uid=sa;pwd=" cnn.execute SQL on error resume next if err<>0 then response.wrITe "错误:"&err.Descripting else response.wrITe "数据恢复成功!" end if %> ACCESS原理一样 复制代码 代码如下: <% '***************************************** function CopyTo(ByVal cFile,ByVal toFile) cFile=Server.MapPath(cFile) ‘所要备份的文件 toFile=Server.MapPath(toFile) ‘备份文件 Dim cFso,cf set cFso=Server.CreateObject("Scripting.FileSystemObject") cFso.fileexists(cFile) cFso.Copyfile cFile,toFile end function '********************************************* ' ASP实现备份及恢复ACCESS数据库操作 '本页面为 databackup.asp dim dbpath,bkfolder,bkdbname,fso,fso1 call main() call main2() conn.close set conn=nothing sub main() if request("action")="Backup" then call backupdata() else %>
数据库备份
当前数据库路径(相对路径):
备份数据库目录(相对路径): 如目录不存在,程序将自动创建
备份数据库名称(填写名称): 如备份目录有该 文件,将覆盖,如没有,将自动创建

<% end if end sub sub main2() if request("action")="Restore" then Dbpath=request.form("Dbpath") backpath=request.form("backpath") if dbpath="" then response.wrITe "请输入您要恢复成的数据库全名" else Dbpath=server.mappath(Dbpath) end if backpath=server.mappath(backpath) Response.wrITe Backpath Set Fso=server.createobject("scripting.filesystemobject") if fso.fileexists(dbpath) then fso.copyfile Dbpath,Backpath response.wrITe "成功恢复数据!" else response.wrITe "备份目录下并无您的备份文件!" end if else %>
恢复数据库
备份数据库路径(相对):
当前数据库路径(相对):

・注意:所有路径都是相对路径
<% end if end sub sub backupdata() Dbpath=request.form("Dbpath") Dbpath=server.mappath(Dbpath) bkfolder=request.form("bkfolder") bkdbname=request.form("bkdbname") Set Fso=server.createobject("scripting.filesystemobject") if fso.fileexists(dbpath) then If CheckDir(bkfolder) = True Then fso.copyfile dbpath,bkfolder& "\\"& bkdbname else MakeNewsDir bkfolder fso.copyfile dbpath,bkfolder& "\\"& bkdbname end if response.wrITe "备份数据库成功,您备份的数据库路径为" &bkfolder& "\\"& bkdbname+"" Else response.wrITe "找不到您所需要备份的文件。" End if end sub '------------------检查某一目录是否存在------------------- Function CheckDir(FolderPath) folderpath=Server.MapPath(".")&"\\"&folderpath Set fso1 = CreateObject("Scripting.FileSystemObject") If fso1.FolderExists(FolderPath) then '存在 CheckDir = True Else '不存在 CheckDir = False End if Set fso1 = nothing End Function '-------------根据指定名称生成目录--------- Function MakeNewsDir(foldername) dim f Set fso1 = CreateObject("Scripting.FileSystemObject") Set f = fso1.CreateFolder(foldername) MakeNewsDir = True Set fso1 = nothing End Function %>

相关内容