https://login.veeam.com/en/oauth?client_id=nXojRrypJ8&redirect_uri=https%3A%2F%2Fwww.veeam.com%2Fservices%2Fauthentication%2Fredirect_url&response_type=code&scope=profile&state=eyJmaW5hbFJlZGlyZWN0TG9jYXRpb24iOiJodHRwczovL3d3dy52ZWVhbS5jb20va2IxOTUzIiwiaGFzaCI6IjgyNThlYmQ3LWJlM2QtNGQwZi1hY2YyLTQ2ZGEzOGU1YThhOSJ9
1-800-691-1991 | 9am - 8pm ET
EN

Failed to execute SQL scripts for Database

Challenge

Upgrade from Veeam Backup & Replication 7 to 8 may fail with "Failed to execute SQL scripts for Database <Databasename>"

 

Cause

The issue is caused by mediapools which are not linked to any library but still contain tape media entries. This may happen when the library or standalone drive was exchanged, and the tape mediapools and media were migrated manually into the new library / standalone drive without cleaning up old entries accordingly.

The logs show issues such as follows:
***Veeam*** SRV: [timestamp]:<00000001> [VEEAM|ERROR] ExecuteNonQuery failed for Database 'VeeamBackup'. (Microsoft.SqlServer.Management.Smo.FailedOperationException)
...
***Veeam*** SRV: [timestamp]:<00000001> [VEEAM|ERROR] Cannot insert the value NULL into column 'media_pool_id', table 'VeeamBackup.dbo.Tape.tape_mediums'; column does not allow nulls. UPDATE fails.

Solution

Execute the following SQL Script to finish the cleanup, after which you can proceed with the upgrade as usual.

USE VeeamBackup

DECLARE @id uniqueidentifier

DECLARE c CURSOR FOR
    SELECT
        t.id
    FROM
        [Tape.tape_mediums] t
        INNER JOIN [Tape.media_pools] m ON t.media_pool_id = m.id
    WHERE
        NOT EXISTS(SELECT * FROM [Tape.libraries] l WHERE l.id = m.library_id)

OPEN c
    
WHILE 1 = 1
BEGIN
    FETCH NEXT FROM c INTO @id
    if (@@FETCH_STATUS <> 0)
        BREAK

    EXEC [Tape.delete_tape_medium_from_catalogue] @tape_medium_id = @id
    DELETE FROM [Tape.tape_mediums] WHERE id = @id
END

CLOSE c
DEALLOCATE c

BEGIN
    DELETE FROM [dbo].[Tape.media_pools]
    WHERE
    NOT EXISTS(SELECT 1 FROM [dbo].[Tape.libraries] l where l.id = library_id)
END


 

More information

Please see the following KB article on how to run SQL scripts: http://www.veeam.com/kb1443
KB ID:
1953
Product:
Veeam Backup & Replication
Version:
8.x
Published:
2014-11-13
Last Modified:
2020-08-13
Please rate how helpful this article was to you:
5 out of 5 based on 1 ratings
Thank you for helping us improve!
An error occurred during voting. Please try again later.

Couldn't find what you were looking for?

Below you can submit an idea for a new knowledge base article.
Report a typo on this page:

Please select a spelling error or a typo on this page with your mouse and press CTRL + Enter to report this mistake to us. Thank you!

Spelling error in text

Knowledge base content request
By submitting, you agree that your personal data will be managed by Veeam in accordance with the Privacy Policy.
Your report was sent to the responsible team. Our representative will contact you by email you provided.
We're working on it please try again later