Click here to Skip to main content

shibashish mohanty asked:

Open original thread
I want to take backup of my server database into my local system.so i have used the following sql query
DECLARE @name VARCHAR(50) -- database name
DECLARE @path VARCHAR(256) -- path for backup files
DECLARE @fileName VARCHAR(256) -- filename for backup
DECLARE @fileDate VARCHAR(20) -- used for file name
 
 
-- specify database backup directory
SET @path = 'C:\Backup\'
 
 
-- specify filename format
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)
 
 
DECLARE db_cursor CURSOR FOR
SELECT name
FROM master.dbo.sysdatabases
WHERE name IN ('Sutra') -- exclude these databases
 
 
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name
 
 
WHILE @@FETCH_STATUS = 0
BEGIN
SET @fileName = @path + @name + '_' + @fileDate + '.BAK'
BACKUP DATABASE @name TO DISK = @fileName
 
 
FETCH NEXT FROM db_cursor INTO @name
END
 
 
CLOSE db_cursor
DEALLOCATE db_cursor
 
i have created the Backup folder in C: drive.but it returns the following error

Msg 3201, Level 16, State 1, Line 28
Cannot open backup device 'C:\Backup\Sutra_20121116.BAK'. Operating system error 3(The system cannot find the path specified.).
Msg 3013, Level 16, State 1, Line 28
BACKUP DATABASE is terminating abnormally.

Please solve it.i have tried with different location.still it is not working.please help me.Thanks in advance
shibashish mohanty
Tags: SQL-Server

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100