I have to make a local copy of a remote SQL Server database. I did this by using Tasks > Backup from Management Studio. I then locally restored the backup, which seems to have everything -- tables, users, symmetric key, and certificate.
When I try to perform a select that requires me to open the symmetric key and decrypt by the certificate, I get this error:
Please create a master key in the database or open the master key in the session before performing this operation.
Why am I being asked for this, and why doesn't it open automatically like it does on the remote server?
I've tried changing the master key, but without the original password, I can't do much.
If the master key cannot be opened, use the RESTORE MASTER KEY statement to restore the master key from a backup. Use the FORCE option only if the master key is irretrievable or if decryption fails. Information that is encrypted only by an irretrievable key will be lost.
To restore the master databaseThe REPLACE option instructs SQL Server to restore the specified database even when a database of the same name already exists. The existing database, if any, is deleted. In single-user mode, we recommend that you enter the RESTORE DATABASE statement in the sqlcmd utility.
To back up the database master key In SQL Server Management Studio, connect to the SQL Server instance containing the database master key you wish to back up. Choose a password that will be used to encrypt the database master key on the backup medium. This password is subject to complexity checks.
The problem is the SMK has changed (since the machine has changed). There's an article explaining it here. Just export and import the SMK -- bearing in mind that any encrypted data in your copied-to system will be unreadable.
MSDN articles:
Here is a good article specifically on migrating a database that includes encryption:
http://www.sql-server-performance.com/2009/migrating-databases-checklist-part3/3/
But in short, you need to know the original password in order to move it.
You can backup and restore the key (i.e. replicate as you mention) but you'll need access to the remote server, ability to create backup, or copy of backup with original passwords:
http://msdn.microsoft.com/en-us/library/ff848768.aspx
This forum conversation may also prove useful for insight:
http://www.sqlservercentral.com/Forums/Topic775644-146-1.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With