|
备份数据库的asp
<%
'***********连接你的sql server****************
Set srv = Server.CreateObject("SQLDMO.SQLServer")
srv.LoginTimeout = 15 '连接超时
srv.Connect "YXY", "xj", "1234"
'************************************************
Dim objDB
Dim objDevice
Set objDevice = Server.CreateObject("SQLDMO.BackupDevice")
Set objDB = Server.CreateObject("SQLDMO.Database")
%>
<form name="form" action="/realestate/weihu/pbackup.asp" method="post" onsubmit="return checkinfo();">
<TABLE>
<TR>
<TD><b>备份集名称:</b></TD>
<TD><INPUT name="fname" size="20" maxlength="50" value="房地产估价 备份" readonly></TD>
</TR>
<TR>
<TD><b>数据库名称:</b></TD>
<TD><SELECT name="fdatabase">
<OPTION value=""></OPTION>
<%
For Each objDB In srv.Databases
If objDB.SystemObject = False Then
%>
<OPTION value="<%=objDB.Name%>"><%=objDB.Name%></OPTION>
<%
End If
Next
%>
</SELECT></TD></TR>
<TR>
<TD><b>动作</b></TD>
<TD><SELECT name="faction">
<OPTION Value="0" selected>备份为完全数据库</OPTION>
<OPTION Value="1">备份为差异数据库</OPTION>
</SELECT>
</TD>
</TR>
<TR>
<TD>备份文件描述: </TD>
<TD><INPUT name="fdescription" size="40" maxlength="255" value="备份房地产估价<%=now()%>" readonly></TD>
</TR>
<TR>
<TD><b>备份文件名称</b>: </TD>
<TD><INPUT name="fbackupfile" size="40" maxlength="50"></TD>
</TR>
</TABLE>
<div align="center">
<INPUT type="SUBMIT" value="备份[B]" id="subreset" accesskey="B">
<INPUT type="reset" value="重置[R]" id="subreset" accesskey="R">
</div>
</FORM>
'***********连接你的sql server****************
Set srv = Server.CreateObject("SQLDMO.SQLServer")
srv.LoginTimeout = 15 '连接超时
srv.Connect "YXY", "xj", "1234"
'************************************************
Dim objBackup
'creating the backup object
set objBackup = Server.CreateObject("SQLDMO.Backup")
'setting the properties
objBackup.BackupSetName = trim(Request("fname"))
objBackup.Database = trim(Request("fdatabase"))
objBackup.Action = trim(Request("fAction"))
objBackup.BackupSetDescription = trim(Request("fdescription"))
objBackup.Files = trim(Request("fbackupfile"))
'开始备份
objBackup.SQLBackup srv
'断开同sql server的连接
srv.disconnect
set srv = nothing
set objBackup = Nothing
---------------------------------------------------------------------
同理可以在ADP,或VB中调 用此法! |
|