展开全部
把下面的代码放到备份按钮里面去,改相关的数据库名称和路径即可
Thread thread = new Thread( new ThreadStart(ThreadProc) );
thread.Start();
SqlConnection conn = db.createcon();//创建连接
SqlCommand cmdBK = new SqlCommand();
cmdBK.CommandType = CommandType.Text;
cmdBK.Connection = conn;
//path存放备份文件的路径
string path;
path=Server.MapPath("备份文件的路径");
cmdBK.CommandText = @"backup database 需要备份的数据库名 to disk='"+path+"' with init";
try
{
conn.Open();
cmdBK.ExecuteNonQuery();
Response.Write("备份成功.备份文件路径");
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
finally
{
conn.Close();
conn.Dispose();
}
thread.Join();
Thread thread = new Thread( new ThreadStart(ThreadProc) );
thread.Start();
SqlConnection conn = db.createcon();//创建连接
SqlCommand cmdBK = new SqlCommand();
cmdBK.CommandType = CommandType.Text;
cmdBK.Connection = conn;
//path存放备份文件的路径
string path;
path=Server.MapPath("备份文件的路径");
cmdBK.CommandText = @"backup database 需要备份的数据库名 to disk='"+path+"' with init";
try
{
conn.Open();
cmdBK.ExecuteNonQuery();
Response.Write("备份成功.备份文件路径");
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
finally
{
conn.Close();
conn.Dispose();
}
thread.Join();
展开全部
1:要用到SQL-SERVER里面的Sqldmo来做这个工作,找到Sqldmo.dll这个文件,在C:\program files\microsoft Sql server
\80\Tools\binn\Sqldmo.dll
用.net框架提供的工具转达成受托管代码(工具为:vs.net命令提示)
tlbimp sqldmo.dll /out: c:\sqldmo.dll
2:引用Sqldmo.dll文件(imports sqldmo)
3: Dim oBackup As sqldmo.Backup = New sqldmo.BackupClass
Dim oSqlServer As sqldmo.SQLServer = New sqldmo.SQLServerClass
oSqlServer.LoginSecure = False
oSqlServer.Connect("luohua", "sa", "密码")
oBackup.Action = SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database
oBackup.Database = "数据库"
oBackup.Files = "d:\jnszf.bak"
oBackup.BackupSetName = "数据库"
oBackup.BackupSetDescription = "数据库备份"
oBackup.Initialize = True
oBackup.SQLBackup(oSqlServer)
oSqlServer.DisConnect()
Dim fi As System.IO.FileInfo = New System.IO.FileInfo("d:\jnszf.bak")
\80\Tools\binn\Sqldmo.dll
用.net框架提供的工具转达成受托管代码(工具为:vs.net命令提示)
tlbimp sqldmo.dll /out: c:\sqldmo.dll
2:引用Sqldmo.dll文件(imports sqldmo)
3: Dim oBackup As sqldmo.Backup = New sqldmo.BackupClass
Dim oSqlServer As sqldmo.SQLServer = New sqldmo.SQLServerClass
oSqlServer.LoginSecure = False
oSqlServer.Connect("luohua", "sa", "密码")
oBackup.Action = SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database
oBackup.Database = "数据库"
oBackup.Files = "d:\jnszf.bak"
oBackup.BackupSetName = "数据库"
oBackup.BackupSetDescription = "数据库备份"
oBackup.Initialize = True
oBackup.SQLBackup(oSqlServer)
oSqlServer.DisConnect()
Dim fi As System.IO.FileInfo = New System.IO.FileInfo("d:\jnszf.bak")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询