Symptoms
Receiving Database Key error after restoring K2 database on new SQL Server instance. Detailed error message:
The key 'SCSSOKey' is not open. Please open the key before using it.
Please create a master key in the database or open the master key in the session before performing this operation. The key 'SCSSOKey' is not open. Please open the key before using it.System.Data.SqlClient.SqlException (0x80131904): Please create a master key in the
Diagnoses
Whenever you move/restore K2 database onto new SQL Server instance it is required for you to rebuild SCSSOKey for K2 database.
Resolution
Resolution:
- Create backup of K2 Database
- Stop the K2 Blackpearl Service
- Run the following SQL scripts:
--1.
ALTER SERVICE MASTER KEY FORCE REGENERATE
--2.
DROP SYMMETRIC KEY SCSSOKey
DROP CERTIFICATE SCHostServerCert
DROP MASTER KEY
CREATE MASTER KEY ENCRYPTION BY PASSWORD = '(Contact K2 Support for this detail)'
--Create certificate
--Modify dates if necessary
CREATE CERTIFICATE SCHostServerCert WITH SUBJECT = ’Host Server Certificate’, START_DATE = '01/01/2007', EXPIRY_DATE = '01/01/2020'
--Create symmetric key
CREATE SYMMETRIC KEY SCSSOKey WITH ALGORITHM = TRIPLE_DES ENCRYPTION BY CERTIFICATE SCHostServerCert
--Grant control on keys
--Replace DomainUser as required
GRANT CONTROL ON SYMMETRIC KEY::SCSSOKey TO nDomainUser]
GRANT CONTROL ON SYMMETRIC KEY::SCSSOKey TO oDomainUser]
GO
--3.
OPEN MASTER KEY DECRYPTION BY PASSWORD = '(Contact K2 Support for this detail)'
ALTER MASTER KEY DROP ENCRYPTION BY SERVICE MASTER KEY
ALTER MASTER KEY ADD ENCRYPTION BY SERVICE MASTER KEY
CLOSE MASTER KEY
GO
- Start the K2 Blackpearl Service
* If you use SQL Server 2016 or newer use AES_256 instead of TRIPLE_DES as starting from SQL Server 2016 TRIPLE_DES encryption algorithm is no longer supported. Just replace "TRIPLE_DES" with "AES_256" in the script 2 above. More details can be found in Microsoft's Documentation.
* In case when non-consolidated K2 databases are being used scripts mentioned above have to be run against the following K2 databases:
1. HostServer
2. K2SQLUM
3. K2SmartBox
4. K2SmartBroker