国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

asp 在線備份與恢復sqlserver數據庫的代碼

2020-07-27 12:50:46
字體:
來源:轉載
供稿:網友
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
%>
<table cellspacing=1 cellpadding=1 align=center width="90%">
<tr>
<th height=25 >
&nbsp;&nbsp;<B>數據庫備份</B>
</th>
</tr>
<form method="post" action="databackup.asp?action=Backup">
<tr>
<td height=100 style="line-height:150%">
&nbsp;&nbsp;
當前數據庫路徑(相對路徑):
<input type=text size=15 name=DBpath value="../mdb/database.mdb"><BR>
&nbsp;&nbsp; 備份數據庫目錄(相對路徑):
<input type=text size=15 name=bkfolder value=../Databackup>&nbsp;如目錄不存在,程序將自動創建<BR>
&nbsp;&nbsp; 備份數據庫名稱(填寫名稱):
<input type=text size=15 name=bkDBname value=database.mdb> &nbsp;如備份目錄有該

文件,將覆蓋,如沒有,將自動創建<BR>
&nbsp;&nbsp;<input type=submIT value="備份數據"><hr align="center" width="90%" color="#999999"></td>
</tr>
</form>
</table>
<%
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 "<font color=red>成功恢復數據!</font>"
else
response.wrITe "<font color=red>備份目錄下并無您的備份文件!</font>"
end if
else
%>
<table align=center cellspacing=1 cellpadding=1 width="90%">
<tr>
<th height=25 >
&nbsp;&nbsp;<B>恢復數據庫</B>
</th>
</tr>
<form method="post" action="databackup.asp?action=Restore">
<tr>
<td height=100 >
&nbsp;&nbsp;備份數據庫路徑(相對):
<input type=text size=30 name=DBpath value="../Databackup/database.mdb">&nbsp;&nbsp;<BR>
&nbsp;&nbsp;當前數據庫路徑(相對):
<input type=text size=30 name=backpath value="../mdb/database.mdb"><BR>
&nbsp;&nbsp;<input type=submIT value="恢復數據"> <hr width="90%" align="center" color="#999999">
&nbsp;&nbsp;<font color="#666666">?注意:所有路徑都是相對路徑 &nbsp;&nbsp;</font></td>
</tr>
</form>
</table>
<%
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& "http://"& bkdbname
else
MakeNewsDir bkfolder
fso.copyfile dbpath,bkfolder& "http://"& bkdbname
end if
response.wrITe "<font color=red>備份數據庫成功,您備份的數據庫路徑為" &bkfolder& "http://"& bkdbname+"</font>"
Else
response.wrITe "<font color=red>找不到您所需要備份的文件。</font>"
End if
end sub
'------------------檢查某一目錄是否存在-------------------
Function CheckDir(FolderPath)
folderpath=Server.MapPath(".")&"http://"&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
%>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 富川| 临潭县| 建水县| 榆树市| 荔波县| 通江县| 滦南县| 九寨沟县| 儋州市| 金坛市| 固安县| 铜陵市| 浏阳市| 香格里拉县| 梁河县| 高陵县| 秦皇岛市| 台南县| 石家庄市| 鄂尔多斯市| 平谷区| 美姑县| 勃利县| 武山县| 彩票| 濉溪县| 凤山县| 大宁县| 内乡县| 甘南县| 淮北市| 东明县| 柞水县| 罗定市| 双柏县| 南平市| 巴林右旗| 阿勒泰市| 平江县| 蒙山县| 内江市|