Trying to create cetificate in SQL 2008 R2 gives error

  • Hi Everyone,

    I have create a master key and am trying to create a certifiacte and keep getting this error "Msg 15581, Level 16, State 3, Line 4

    Please create a master key in the database or open the master key in the session before performing this operation."

    Below is my code to create the certificate.

    IF NOT EXISTS (SELECT * FROM sys.certificates

    WHERE [name] = 'config_cert')

    CREATE CERTIFICATE config_cert

    --AUTHORIZATION enc_user

    WITH SUBJECT = 'X.509 encryption certificate for securing configuration symmetric keys.';

    GO

    Code to create the master key

    IF NOT EXISTS (SELECT * FROM sys.symmetric_keys

    WHERE [name] Like '%DatabaseMasterKey%')

    CREATE MASTER KEY ENCRYPTION BY PASSWORD = 1234xyz!';

    GO

    What am I doing wrong?

    Please help.

  • Your master key is not automatically opening. Perhaps it wasn't created with encryption by the SMK as well?

    Try:

    OPEN MASTER KEY BY PASSWORD = 'XXX'

    CREATE CERTIFICATE XXX

    http://msdn.microsoft.com/en-us/library/ms174433.aspx]OPEN MASTER KEY

  • so you have to open the master key to create a certificate?

  • You shouldn't have to explicitly. It does have to be open, but if you just ran this, then the SMK should automatically open it.

    If this is all your code, then you have a typo in the password (missing quote).

    I assume you are running the code in the reverse order, correct? Master key first, then cert?

  • Just a tip also when create the mirror make sure you specify the expiry date for the certificate otherwise it will default to one year.

    “When I hear somebody sigh, ‘Life is hard,’ I am always tempted to ask, ‘Compared to what?’” - Sydney Harris

  • Shabnam Gupta (5/17/2012)


    so you have to open the master key to create a certificate?

    What does the following query return?

    select name, is_master_key_encrypted_by_server from sys.databases

    where database_id = 1

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply