开发者

Backup SQL Server database in ASP.NET

I want to backup a SQL Server database with C#. I have written a stored procedure which backup the database:

CREATE PROCEDURE WINC_BackupDatabase
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedur开发者_如何学运维e here
    BACKUP DATABASE WINC_kentico
    TO DISK = 'G:\MSSQL10.MSSQLSERVER\MSSQL\Backup\WINC_kentico_' + NOW() + '.bak'
    WITH NOINIT
END
GO

In line 10 I set the path for the backup. I want to add the current DateTime at the end of the file name. How is the syntax to set a DataTime at the end of the file name?

Best regards


DECLARE @NAME VARCHAR(250);
SET @NAME = 'G:\MSSQL10.MSSQLSERVER\MSSQL\Backup\WINC_kentico_' + CONVERT(VARCHAR,GETDATE(),112) + '.bak';
BACKUP DATABASE WINC_kentico
TO DISK = @NAME
WITH NOINIT
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜