TDE Restore Fails: Cannot Find Server Certificate (Error 33111)

🚨Part of the SQL Server Errors series, the exact messages and what actually causes them.In: Backup & Recovery

You are restoring a TDE database on a different server, or on a rebuilt one, and the restore stops at Msg 33111. The backup is fine. This server is missing the certificate that protects the database’s encryption key, so it cannot read a single page. Create that certificate in master from its backup files and the same restore goes through.

Msg 33111  ·  Level 16  ·  State 3
Cannot find server certificate with thumbprint '0x1E42F5974A21BC7B9F5DF393D072C9D5FD61705F'.

It is followed by Msg 3013, RESTORE DATABASE is terminating abnormally, which adds nothing. The thumbprint in your message will be different, and it is the one part of the message you need.

⚡Copy the thumbprint out of the message and look for it in master.sys.certificates on this server. No row: the certificate is missing, so create it from the .cer and .pvk backup files and rerun the restore. A row with NO_PRIVATE_KEY, or a different error once it exists: the private key did not come across. An expired certificate is not the cause.

Find the Certificate the Backup Needs

A TDE backup names its certificate by thumbprint, not by name. Paste the thumbprint from your message into this query on the server you are restoring to:

-- Paste the thumbprint from the 33111 message, no quotes
SELECT name, subject, thumbprint, pvt_key_encryption_type_desc, expiry_date
FROM master.sys.certificates
WHERE thumbprint = 0x1E42F5974A21BC7B9F5DF393D072C9D5FD61705F;

No row means the certificate is not on this server, which is the usual case. Checking the backup file will not get you further: RESTORE FILELISTONLY and RESTORE VERIFYONLY stop at the same error, because both have to read inside the encrypted backup.

RESTORE FILELISTONLY and VERIFYONLY with the certificate missingexample output, not something to copy
Msg 33111, Level 16, State 3, Server HPAI01, Line 1 Cannot find server certificate with thumbprint '0x1E42F5974A21BC7B9F5DF393D072C9D5FD61705F'. Msg 3013, Level 16, State 1, Server HPAI01, Line 1 RESTORE FILELIST is terminating abnormally. Msg 33111, Level 16, State 3, Server HPAI01, Line 1 Cannot find server certificate with thumbprint '0x1E42F5974A21BC7B9F5DF393D072C9D5FD61705F'. Msg 3013, Level 16, State 1, Server HPAI01, Line 1 VERIFY DATABASE is terminating abnormally.

RESTORE HEADERONLY still works, and its ServerName and DatabaseName columns tell you which server to ask for the certificate. Ignore its EncryptorThumbprint column, which read NULL on this TDE backup: it belongs to backup encryption, a separate feature (RESTORE HEADERONLY on MS Docs).


Get the Certificate From the Source Server

If somebody already has the certificate backup, the .cer file, the .pvk private key file and the password that protects it, skip to the next section. If the source server is still running, this shows which certificate protects each TDE database there:

-- Run on the SOURCE server
SELECT DB_NAME(k.database_id) AS database_name,
       k.encryption_state_desc,          -- 2019 and later; use encryption_state on older builds
       c.name AS certificate_name,
       k.encryptor_thumbprint,
       c.pvt_key_last_backup_date
FROM sys.dm_database_encryption_keys AS k
LEFT JOIN master.sys.certificates AS c ON c.thumbprint = k.encryptor_thumbprint
WHERE k.database_id > 4;

Then back the certificate up with its private key. The private key is the part that matters: without it the certificate is only a public key, and the restore still fails (see below).

USE master;
BACKUP CERTIFICATE TDECert
TO FILE = 'D:\CertBackup\TDECert.cer'
WITH PRIVATE KEY (
    FILE = 'D:\CertBackup\TDECert.pvk',
    ENCRYPTION BY PASSWORD = '<a strong password you will store safely>'
);

Copy both files to the target server, somewhere the SQL Server service account can read, and keep the password with them. The syntax is on BACKUP CERTIFICATE on MS Docs.


Create the Certificate on This Server, Then Restore

The certificate goes in master on the target, and master needs a database master key to hold its private key. Check for one first:

USE master;
SELECT name FROM sys.symmetric_keys WHERE name = '##MS_DatabaseMasterKey##';

-- No row? Create one. This is a NEW password for this server, it does not have to match the source.
-- CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<a strong password you will store safely>';

Then create the certificate from the two files. The password here is the one used when the certificate was backed up, not the master key password:

USE master;
CREATE CERTIFICATE TDECert
FROM FILE = 'D:\CertBackup\TDECert.cer'
WITH PRIVATE KEY (
    FILE = 'D:\CertBackup\TDECert.pvk',
    DECRYPTION BY PASSWORD = '<the password used in BACKUP CERTIFICATE>'
);

-- Confirm the thumbprint now matches the one in the 33111 message
SELECT name, thumbprint, pvt_key_encryption_type_desc
FROM sys.certificates
WHERE thumbprint = 0x1E42F5974A21BC7B9F5DF393D072C9D5FD61705F;

pvt_key_encryption_type_desc should read ENCRYPTED_BY_MASTER_KEY. Now run the same RESTORE DATABASE statement that failed, unchanged. Here the certificate was created under a different name from the source, and the restore still worked, because only the thumbprint has to match:

The same restore after CREATE CERTIFICATE FROM FILEexample output, not something to copy
Processed 616 pages for database 'Lab1006_c33_restored', file 'Lab1006_c33_db' on file 1. Processed 2 pages for database 'Lab1006_c33_restored', file 'Lab1006_c33_db_log' on file 1. RESTORE DATABASE successfully processed 618 pages in 0.030 seconds (160.807 MB/sec). database_name encryption_state_desc certificate_name encryptor_thumbprint Lab1006_c33_restored ENCRYPTED Lab1006_c33_renamed 0x1E42F5974A21BC7B9F5DF393D072C9D5FD61705F

The restored database stays encrypted by that certificate, so back the certificate up on this server too. The full move is on MS Docs as move a TDE protected database to another SQL Server, and the file options are on CREATE CERTIFICATE.


When the Certificate Is There and the Restore Still Fails

A certificate without its private key, or a private key that never loaded, gives a different message. Each of these came from creating the certificate the wrong way:

  • Msg 15507, “A key required by this operation appears to be corrupted.” The certificate was created from the .cer file alone. The thumbprint matches, pvt_key_encryption_type_desc reads NO_PRIVATE_KEY, and the restore fails. Drop it and create it again with the .pvk file. Nothing is corrupt.
  • Msg 15465, “The private key password is invalid.” The DECRYPTION BY PASSWORD is not the one used in BACKUP CERTIFICATE. The certificate is not created at all, so run it again with the right password.
  • Msg 15581, “Please create a master key in the database or open the master key in the session before performing this operation.” There is no database master key where you ran CREATE CERTIFICATE. Create one in master first (CREATE MASTER KEY on MS Docs). Reproduced in a user database with no master key rather than in master, which already had one.

The 15507 case is the one that wastes time, because the thumbprint check passes:

A certificate created from the .cer file only, then the restoreexample output, not something to copy
name thumbprint pvt_key_encryption_type_desc Lab1006_c33_cert 0x1E42F5974A21BC7B9F5DF393D072C9D5FD61705F NO_PRIVATE_KEY Msg 15507, Level 16, State 30, Server HPAI01, Line 1 A key required by this operation appears to be corrupted. Msg 3013, Level 16, State 1, Server HPAI01, Line 1 RESTORE DATABASE is terminating abnormally.

If the master key itself is the problem, a wrong password or a key the service master key no longer opens, the database master keys post covers those messages, including 15466.


Before the Next Restore Needs It

  • Back up every TDE certificate with its private key the day TDE goes on, and keep the files and the password off the server they protect. MS Docs on TDE is plain about it: without those backups, a database restored or attached on another server cannot be opened.
  • Keep the old certificate after rotating the protector or turning TDE off. MS Docs says parts of the log can stay protected by it, and backups taken before the change still need it.
  • Create the certificate on DR and test servers before the day you need them, and do a test restore there.
  • Audit which certificate protects which database, and when its private key was last exported, with the certificates, keys and TDE status scripts.

Frequently Asked Questions

The certificate has expired. Is that why the restore fails?
No. Expiry is not enforced for TDE. A database protected by a certificate that had expired restored and read normally once that certificate was present on the target. MS Docs on TDE: “You can still use a certificate that exceeds its expiration date to encrypt and decrypt data with TDE.” What blocks the restore is the certificate being missing, expired or not.
A certificate with the same name exists on this server. Why does it still fail?
Because the name does not matter. The backup records the thumbprint, and two certificates created separately with the same name have different thumbprints. Compare the thumbprint in the message with sys.certificates; a certificate created from the right files under any name works.
Which password do I need, the master key password or the certificate password?
The certificate one: the password given to ENCRYPTION BY PASSWORD when the certificate was backed up, which you give as DECRYPTION BY PASSWORD on the target. The target’s master key has its own password, and MS Docs confirms the two do not have to match. Without the certificate password the .pvk file cannot be opened, and without the private key the database cannot be read.
Can I restore it on an older version of SQL Server once the certificate is there?
No. A backup from a newer version will not restore on an older one, TDE or not, and that fails with its own error. See Restore From a Newer SQL Server Version (Error 3169). Check the edition too: before SQL Server 2019, TDE needed Enterprise edition.
Does restoring a TDE database change anything for the other databases on this server?
Yes, one thing. tempdb is encrypted as soon as any database on the instance uses TDE, which MS Docs notes can affect performance for the unencrypted databases too. Worth knowing before you restore onto a shared server.

Where To Go Next

TDE restores go wrong at the certificate, at the master key, or at the backup file itself. The neighbours:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *