using System;
using SystemData;
using SystemConfiguration;
using SystemWeb;
using SystemWebSecurity;
using SystemWebUI;
using SystemWebUIWebControls;
using SystemWebUIWebControlsWebParts;
using SystemWebUIHtmlControls;
using SystemDataSqlClient;
public partial class _Default : SystemWebUIPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string path=@"c:\Testbak";
string backupstr="backup database Test to disk='"+path+"';";
SqlConnection con = new SqlConnection("server=;uid=sa;pwd=;");
SqlCommand cmd = new SqlCommand(backupstr, con);
try
{
conOpen();
cmdExecuteNonQuery();
thisLabel1Text = "备份成功!";
}
catch
{
thisLabel1Text = "备份失败!";
}
finally
{
conClose();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string path = @"c:\Testbak";
string restore="restore database Test from disk='"+path+"';";
SqlConnection con=new SqlConnection("server=;uid=sa;pwd=;");
SqlCommand cmd=new SqlCommand(restore,con);
try
{
conOpen();
cmdExecuteNonQuery();
thisLabel1Text = "恢复成功";
}
catch
{
thisLabel1Text = "恢复失败";
}
finally
{
conClose();
}
}
}
通常,ASPNET无法实现自动备份,因为,在网站空闲时,web服务器会收回ASPNET进程,导致定时器失败(也有通过代码,让网站总是繁忙,这样web服务器就不会收回他的)。
但是,基本上推荐还是用windows服务或者exe实现数据库备份。
从技术上而言,本身,使用NET实现数据库备份非常简单。
string db="XXX";string sql = " use " + db + "; backup database " + db + " to disk=@'c:\back\abcbak'";
只要使用SqlCommand对象执行上面SQL,即可备份数据库。
sub backupdata()
Dbpath=requestform("Dbpath")
Dbpath=servermappath(Dbpath)
bkfolder=requestform("bkfolder")
bkdbname=requestform("bkdbname")
Set Fso=servercreateobject("scriptingfilesystemobject")
if fsofileexists(dbpath) then
If CheckDir(bkfolder) = True Then
fsocopyfile dbpath,bkfolder& "\"& bkdbname
else
MakeNewsDir bkfolder
fsocopyfile dbpath,bkfolder& "\"& bkdbname
end if
responsewrite "备份数据库成功,您备份的数据库路径为<br>" &bkfolder& "\"& bkdbname
Else
responsewrite "找不到您所需要备份的文件。"
End if
end sub
以上就是关于asp.net在后台怎么对Sql Server 数据库备份全部的内容,包括:asp.net在后台怎么对Sql Server 数据库备份、ASP.NET网站能够实现数据库自动定时备份吗、怎么用ASP语句备份Mysql数据库,,,,等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)