Search code examples
sqlsql-serversql-server-2014sql-server-2016

Error when trying to backup data from SQL Server


I'm getting a disturbing and continuous error when I'm trying to do a backup in my database. I have done the research on this subject but I could not get it fixed. Please anyone with the knowledge, suggest the best way of solving it. Here is the error message below: I tried changing .dll files, no chance!!!

enter image description here


Solution

  • You can do an automatic script like this:

    DECLARE @path VARCHAR(500)
    DECLARE @name VARCHAR(500)
    DECLARE @filename VARCHAR(256)
    DECLARE @time DATETIME
    DECLARE @year VARCHAR(4)
    DECLARE @month VARCHAR(2)
    DECLARE @day VARCHAR(2)
    DECLARE @hour VARCHAR(2)
    DECLARE @minute VARCHAR(2)
    DECLARE @second VARCHAR(2)
    
    -- 2. Setting the backup path
    
    SET @path = 'D:\Backup\'  
    
     -- 3. Getting the time values
    
    SELECT @time = GETDATE()
    SELECT @year   = (SELECT CONVERT(VARCHAR(4), DATEPART(yy, @time)))
    SELECT @month  = (SELECT CONVERT(VARCHAR(2), FORMAT(DATEPART(mm,@time),'00')))
    SELECT @day    = (SELECT CONVERT(VARCHAR(2), FORMAT(DATEPART(dd,@time),'00')))
    SELECT @hour   = (SELECT CONVERT(VARCHAR(2), FORMAT(DATEPART(hh,@time),'00')))
    SELECT @minute = (SELECT CONVERT(VARCHAR(2), FORMAT(DATEPART(mi,@time),'00')))
    SELECT @second = (SELECT CONVERT(VARCHAR(2), FORMAT(DATEPART(ss,@time),'00')))
    
    -- 4. Defining cursor operations
    
    DECLARE db_cursor CURSOR FOR  
    SELECT name 
    FROM master.dbo.sysdatabases 
    WHERE name NOT IN ('master','model','msdb','tempdb')  -- system databases are excluded
    
    --5. Initializing cursor operations
    
    OPEN db_cursor   
    FETCH NEXT FROM db_cursor INTO @name   
    
    WHILE @@FETCH_STATUS = 0   
    BEGIN
    
    -- 6. Defining the filename format
    
           SET @fileName = @path + @name + '_' + @year + @month + @day + @hour + @minute + @second + '.BAK'  
           BACKUP DATABASE @name TO DISK = @fileName  
    
    
           FETCH NEXT FROM db_cursor INTO @name   
    END   
    CLOSE db_cursor   
    DEALLOCATE db_cursor
    

    Then put this in a SQL Job step and schedule it daily like this:

    Create new job under SQL Job Agent and add new step enter image description here

    Add an schedule enter image description here

    Job Created with an schedule enter image description here

    Result enter image description here