使用存储过程从硬盘备份MS-SQL数据库? [英] Backing up a MS-SQL database from hard disk with stored procedures?
本文介绍了使用存储过程从硬盘备份MS-SQL数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用以下方法在硬盘上备份数据库:
I can backup a database on hard disk with the following method :
void BackUp(string ConnectionString, string DatabaseFullPath, string backUpPath)
{
progressBar1.Value = 0;
using (SqlConnection con = new SqlConnection(ConnectionString))
{
con.Open();
string UseMaster = "USE master";
SqlCommand UseMasterCommand = new SqlCommand(UseMaster, con);
UseMasterCommand.ExecuteNonQuery();
progressBar1.Value += 25;
string Alter1 = @"ALTER DATABASE [" + DatabaseFullPath + "] SET Single_User WITH Rollback Immediate";
SqlCommand Alter1Cmd = new SqlCommand(Alter1, con);
Alter1Cmd.ExecuteNonQuery();
progressBar1.Value += 25;
string Restore = @"BACKUP DATABASE [" + DatabaseFullPath + "] TO DISK = N''" + backUpPath + @"'' WITH NOFORMAT, NOINIT, NAME = N''" + DatabaseFullPath + "-Full Database Backup'', SKIP, NOREWIND, NOUNLOAD, STATS = 10";
SqlCommand RestoreCmd = new SqlCommand(Restore, con);
RestoreCmd.ExecuteNonQuery();
progressBar1.Value += 25;
string Alter2 = @"ALTER DATABASE [" + DatabaseFullPath + "] SET Multi_User";
SqlCommand Alter2Cmd = new SqlCommand(Alter2, con);
Alter2Cmd.ExecuteNonQuery();
progressBar1.Value += 25;
labelReport.Text = "Successful";
}
}
并且,如何将其转换为存储过程?
(我是MS-SQL中的新手)
and , How can I convert it to a Stored Procedure ?
(I''m newbie in MS-SQL)
推荐答案
在调试该代码时,请在代码中放置断点,并将在命令中执行的所有查询移动到存储过程.
对于查询中的每个参数,在存储过程中创建一个参数.
While debugging this code, put break points in the code and move whatever query you excute in the commands to a stored procedure.
For each of the parameters in the query, create a paramter in the stored procedure.
这篇关于使用存储过程从硬盘备份MS-SQL数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文