locked
Error - Invalid zero-length device name. Reissue the BACKUP statement with a valid device name. RRS feed

  • Question

  • User1979860870 posted

    Hi

       In below code i am getting above error

    	DECLARE @path NVARCHAR(256) -- path for backup files  
    	DECLARE @fileName NVARCHAR(256) -- filename for backup  
    	DECLARE @fileDate NVARCHAR(20) -- used for file name
     
    	-- specify database backup directory
    	SET @path = 'c:\Backup\'  
    	SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) 
     
    	BEGIN   
    	   SET @fileName = @path + @name + '_' + @fileDate + '.BAK'  
    	   BACKUP DATABASE Test TO DISK = @fileName  
    	END   

    Thanks

    Friday, August 14, 2020 11:03 AM

All replies

  • User753101303 posted

    Hi,

    I suspect @name (not even declared, you didn't show this part of the code?) could be NULL causing @filename to be  NULL which seems to match an error message such as an "invalid zero length device name".

    Don't just read the code but also see what it does especially here as it seems the only problem could be the value stored in @filename.

    Friday, August 14, 2020 11:54 AM