开发者

Tsql DB Backup C#

I am using the following query to take backup with backup file name as current timestamp and path as selected by the user(stored in labelbackupPath).

    UtilityClass.ExecuteQuery(@"Declare @file_name varchar(500);
                                set @file_name = CURRENT_TIMESTAMP;
                                BACKUP DATABASE V开发者_开发技巧egiManager to DISK CONCAT(@pathname,@file_name);", true, new SqlParameter("@pathname", labelbackupPath.Text + @"\"));

Here is the signature of ExecuteQuery:

  public static int ExecuteQuery(String query, bool showMsgBox, params SqlParameter[] parameters)

It just executes the specified query adding the specified parameters to the SqlCommand. If showMsgBox is true, it ask for confirmation and gives the result of query execution.

There is some error in the TSql part, please suggest where am I wrong.


CONCAT is not a valid TSQL statement.

You would just append the strings with @pathname + @file_name

I would personally put this backup information into a stored proc and just execute this with parameters passed in.

Also best if doing in code use SQL SMO e.g http://social.msdn.microsoft.com/forums/en-US/sqlexpress/thread/95750bdf-fcb1-45bf-9247-d7c0e1b9c8d2/

Note: The user executing would also require backup permissions and the path needs to be available to server i.e if you backup to C:\temp this is on the server not the machine running the backup.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜