{"id":44986,"date":"2026-06-09T17:01:28","date_gmt":"2026-06-09T15:01:28","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/?p=44986"},"modified":"2026-06-09T17:01:28","modified_gmt":"2026-06-09T15:01:28","slug":"sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/","title":{"rendered":"SQL Server Always On Availability Groups and Database Master Keys: A Hidden Failover Pitfall"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I recently came across an interesting case involving a client whose application used SQL Server symmetric keys to encrypt sensitive data. The database was hosted in an Always On Availability Group environment for high-availability and disaster-recovery.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The interesting and challenging aspect of this setup is ensuring that the encryption and decryption remains intact after a failover. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This challenge originates from SQL Server&#8217;s encryption hierarchy. In a typical setup, the Service Master Key (SMK) on server level protects the Database Master Key (DMK) on database level. The Database Master Key, in turn, protects certificates and asymmetric keys, while certificates are commonly used to protect symmetric keys. These symmetric keys may then be used by the application to encrypt and decrypt sensitive data.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image.png\" alt=\"\" class=\"wp-image-44987\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When a failover to a secondary replica occurs, the Service Master Key (SMK) is no longer the same as on the previous primary replica. Since the Database Master Key (DMK) is typically encrypted by the local Service Master Key, SQL Server may no longer be able to open the DMK transparently after the failover. As a result, any encryption objects that depend on the DMK, such as certificates and symmetric keys, may become inaccessible, potentially causing application failures when encrypted data needs to be read or written.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s now explore the built-in approaches in SQL Server to ensure that the encryption hierarchy remains functional across replicas and that applications continue to operate seamlessly after a failover.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, let&#8217;s create a test database and a Database Master Key:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; notranslate\">\n-- Create Demo DB\nCREATE DATABASE TestDMK;\nGO\n--Backup DB\nBACKUP DATABASE TestDMK\nTO DISK = &#039;C:\\SQLServer_mnt\\BACKUP\\TestDMK.bak&#039;;\ngo\n-- Create Database Master Key\nCREATE MASTER KEY\nENCRYPTION BY PASSWORD = &#039;MyVeryStrongPassword_123!&#039;;\nGO\n-- Check Master Key\nSELECT DB_NAME() as DB, *\nFROM sys.symmetric_keys\nWHERE name = &#039;##MS_DatabaseMasterKey##&#039;;\nGO\n\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-1.png\" alt=\"\" class=\"wp-image-44988\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">It is worth noting that you can verify whether a Database Master Key is also encrypted by the Service Master Key by querying the <strong>sys.databases<\/strong> catalog view. When a Database Master Key is created, SQL Server typically adds encryption by the Service Master Key automatically. This behaviour can be changed by explicitly removing the Service Master Key encryption.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; notranslate\">\nselect is_master_key_encrypted_by_server, * from sys.databases where name = &#039;TestDMK&#039;\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-2.png\" alt=\"\" class=\"wp-image-44989\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">With the Database Master Key in place, let&#8217;s create a certificate and a symmetric key that will be used throughout the remainder of this demonstration.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; notranslate\">\nCREATE CERTIFICATE &#x5B;mainDBCert] --&gt; This cert is going to be encrypted by the dmk\nWITH SUBJECT = &#039;test Cert&#039;;\ngo\nCREATE SYMMETRIC KEY mainKey\nWITH ALGORITHM = AES_256\nENCRYPTION BY CERTIFICATE mainDBCert;\ngo\nSELECT * FROM sys.certificates;\nSELECT * FROM sys.symmetric_keys WHERE name &lt;&gt; &#039;##MS_DatabaseMasterKey##&#039;;\nSELECT * FROM sys.symmetric_keys;\ngo\n\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-3.png\" alt=\"\" class=\"wp-image-44990\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">To demonstrate the encryption and decryption process, let&#8217;s create a simple table that will contain sensitive information and insert some data.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; notranslate\">\n--create table with sensitive data\nCREATE TABLE CreditCards\n(\n    Id int,\n    CreditCardNr varbinary(max),\n    CVC varbinary(max),\n    ExpirationDate varbinary(max)\n);\ngo\n--open symmetric key\nOPEN SYMMETRIC KEY mainKey\nDECRYPTION BY CERTIFICATE mainDBCert;\n--insert sensitive data\nINSERT INTO Cred\u00eetCards\nVALUES\n(\n    1,\n    EncryptByKey(Key_GUID(&#039;mainKey&#039;), &#039;1234-5678-9012-3456&#039;),\n    EncryptByKey(Key_GUID(&#039;mainKey&#039;), &#039;123&#039;),\n    EncryptByKey(Key_GUID(&#039;mainKey&#039;), &#039;1233&#039;)\n);\nCLOSE SYMMETRIC KEY mainKey;\nGO\nSelect * from CreditCards\n\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-21.png\" alt=\"\" class=\"wp-image-45008\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">If we query the table without opening the symmetric key and decrypting the values, we can see that we won\u2019t see the data.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; notranslate\">\n--select data without decryption\nSELECT\n    Id,\n    CONVERT(varchar(50), CreditCardNr) AS CreditCardNr,\n    CONVERT(varchar(10), CVC) AS CVC,\n    CONVERT(varchar(10), ExpirationDate) AS ExpirationDate\nFROM CreditCards;\n\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-5.png\" alt=\"\" class=\"wp-image-44992\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">However, if we open the symmetric key first and use it to decrypt the data, we are able to retrieve the original sensitive information:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; notranslate\">\nOPEN SYMMETRIC KEY mainKey\nDECRYPTION BY CERTIFICATE mainDBCert;\nGO\nSELECT\n    Id,\n    CONVERT(varchar(50), DecryptByKey(CreditCardNr)) AS CreditCardNr,\n    CONVERT(varchar(10), DecryptByKey(CVC)) AS CVC,\n    CONVERT(varchar(10), DecryptByKey(ExpirationDate)) AS ExpirationDate\nFROM Cred\u00eetCards;\nGO\nCLOSE SYMMETRIC KEY mainKey;\nGO\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-6.png\" alt=\"\" class=\"wp-image-44993\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s add our database to an Always On Availability Group to provide high availability and disaster recovery. If you follow the Availability Group wizard, you may notice that the wizard asks you to enter a password. What the wizards is asking for here is the password of the Database Master Key (DMK). The DMK protects the certificate in our encryption hierarchy, and the certificate, in turn, protects the symmetric key used to encrypt and decrypt the sensitive data.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-7.png\" alt=\"\" class=\"wp-image-44994\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-9.png\" alt=\"\" class=\"wp-image-44996\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">On the right-hand side of the wizard, there is a small and easily overlooked text box where you can enter the Database Master Key password.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-10.png\" alt=\"\" class=\"wp-image-44997\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">And now comes the tricky &#8211; and at the same time somewhat surprising &#8211; part. If you use automatic seeding, which is my preferred option whenever the database size allows it, the process will skip the part where the Master Key password is verified and applied on the secondary replicas.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-11.png\" alt=\"\" class=\"wp-image-44998\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">As a result, when a failover occurs, SQL Server would no longer be able to open the Database Master Key (DMK) transparently on the new primary replica. Consequently, the application would no longer be able to encrypt or decrypt data unless the Database Master Key is explicitly opened first with the password.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-12.png\" alt=\"\" class=\"wp-image-44999\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-13.png\" alt=\"\" class=\"wp-image-45000\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In such a scenario, the issue can be resolved by storing the Database Master Key password as a credential on each replica using the <strong>sp_control_dbmasterkey_password <\/strong>stored procedure. SQL Server can then use this credential to automatically open the Database Master Key after a failover, allowing the encryption hierarchy to remain intact and ensuring that certificates, symmetric keys, and encrypted data remain accessible transparently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>!!Note that you must do that on each replica!!<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; notranslate\">\nsp_control_dbmasterkey_password @db_name = N&#039;TestDMK&#039;\n    , @password = N&#039;MyVeryStrongPassword_123!&#039;\n    , @action = N&#039;add&#039;;\nselect * from sys.master_key_passwords;\nselect * from sys.credentials;\n\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-14.png\" alt=\"\" class=\"wp-image-45001\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Once the credential has been created, SQL Server is again able to open the Database Master Key transparently. As a result, the application can continue to encrypt and decrypt data without having to explicitly open the Master Key with the password.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-15.png\" alt=\"\" class=\"wp-image-45002\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">There is also an option by which SQL Server automatically creates the Database Master Key credential across all replicas when a database is joined to an Availability Group. This happens when <strong>&#8220;Full Database Backup and Log Backup&#8221;<\/strong> is selected as the initial data synchronization option in the Availability Group wizard.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To demonstrate this, let&#8217;s remove the previously created credential using the same stored procedure.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; notranslate\">\nsp_control_dbmasterkey_password @db_name = N&#039;TestDMK&#039;\n    , @password = N&#039;MyVeryStrongPassword_123!&#039;\n    , @action = N&#039;drop&#039;;\nselect * from sys.master_key_passwords;\nselect * from sys.credentials;\n\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-16.png\" alt=\"\" class=\"wp-image-45003\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now, let&#8217;s select <strong>&#8220;Full Database and Log Backup&#8221;<\/strong> as the initial data synchronization option in the Availability Group wizard.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-17.png\" alt=\"\" class=\"wp-image-45004\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see, the process is no longer skipping the Database Master Key password validation step.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-18.png\" alt=\"\" class=\"wp-image-45005\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In the summary, you can see that the process automatically created the Database Master Key password credential on each replica.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-19.png\" alt=\"\" class=\"wp-image-45006\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">If you check the credentials on each replica afterwards, you can verify that they were created automatically.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image-20.png\" alt=\"\" class=\"wp-image-45007\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">As the Database Master Key password credential has been added to all replicas, SQL Server can transparently open the DMK after a failover. As a result, the application can continue to encrypt and decrypt data without having to explicitly open the Database Master Key.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>But one question still puzzles me:<\/strong> why the same operation isn&#8217;t performed automatically when automatic seeding is used?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Honestly, I have no clue yet. If you know more let me know it in the comments section. I&#8217;d love to learn more about it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks for reading \u2013 Hocine \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently came across an interesting case involving a client whose application used SQL Server symmetric keys to encrypt sensitive data. The database was hosted in an Always On Availability Group environment for high-availability and disaster-recovery. The interesting and challenging aspect of this setup is ensuring that the encryption and decryption remains intact after a&hellip;&nbsp;<\/p>\n","protected":false},"author":145,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","neve_meta_reading_time":"","_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[4133,99],"tags":[652,790,447,84],"class_list":["post-44986","post","type-post","status-publish","format-standard","category-database","category-sql-server","tag-data","tag-disaster-recovery","tag-encryption","tag-high-availability"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.9 (Yoast SEO v28.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>SQL Server Always On Availability Groups and Database Master Keys: A Hidden Failover Pitfall - dbi services Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server Always On Availability Groups and Database Master Keys: A Hidden Failover Pitfall\" \/>\n<meta property=\"og:description\" content=\"I recently came across an interesting case involving a client whose application used SQL Server symmetric keys to encrypt sensitive data. The database was hosted in an Always On Availability Group environment for high-availability and disaster-recovery. The interesting and challenging aspect of this setup is ensuring that the encryption and decryption remains intact after a&hellip;&nbsp;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi services Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/dbiservices\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-06-09T15:01:28+00:00\" \/>\n<meta name=\"author\" content=\"Hocine Mechara\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@dbiservices\" \/>\n<meta name=\"twitter:site\" content=\"@dbiservices\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hocine Mechara\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\\\/\"},\"author\":{\"name\":\"Hocine Mechara\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/dfd8f6b358f95eeca793ccffbab73eb4\"},\"headline\":\"SQL Server Always On Availability Groups and Database Master Keys: A Hidden Failover Pitfall\",\"datePublished\":\"2026-06-09T15:01:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\\\/\"},\"wordCount\":975,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/06\\\/image.png\",\"keywords\":[\"data\",\"disaster recovery\",\"encryption\",\"High Availability\"],\"articleSection\":[\"Database\",\"SQL Server\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\\\/\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\\\/\",\"name\":\"SQL Server Always On Availability Groups and Database Master Keys: A Hidden Failover Pitfall - dbi services Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/06\\\/image.png\",\"datePublished\":\"2026-06-09T15:01:28+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\\\/#primaryimage\",\"url\":\"\",\"contentUrl\":\"\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server Always On Availability Groups and Database Master Keys: A Hidden Failover Pitfall\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\",\"name\":\"dbi services Blog\",\"description\":\"#BeSharing\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\",\"name\":\"dbi services\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/dbi-services-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/dbi-services-logo.png\",\"width\":512,\"height\":512,\"caption\":\"dbi services\"},\"image\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/dbiservices\\\/\",\"https:\\\/\\\/x.com\\\/dbiservices\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/dbi-services\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/dbiservices\"],\"description\":\"Swiss IT consulting and services company specialized in efficient data infrastructures and platforms: databases, application servers, cloud, DevOps, digitalization, analytics, data quality and monitoring. Headquartered in Del\u00e9mont with offices in Nyon, Basel, Bern and Zurich.\",\"email\":\"info@dbi-services.com\",\"telephone\":\"+41 32 422 96 00\",\"legalName\":\"dbi services SA\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/dfd8f6b358f95eeca793ccffbab73eb4\",\"name\":\"Hocine Mechara\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/HME_web.jpg\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/HME_web.jpg\",\"contentUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/HME_web.jpg\",\"caption\":\"Hocine Mechara\"},\"description\":\"Hocine Mechara has more than 5 years of experience in IT and specializes in SQL Server databases. His expertise includes installing and configuring SQL Server instances (stand-alone, Always On, FCI), migrating SQL Server databases, and operating SQL Server instances and databases, as well as Azure SQL Services and more. Hocine is a Microsoft Certified Database Administrator Associate, a Certified Administrator for SUSE Linux Enterprise Server 15, and a HashiCorp Certified Terraform Associate. He also holds a Swiss Federal Certificate of Competence as an IT Systems Engineer. Prior to joining dbi services, he worked at T-Systems Switzerland AG as a Database Engineer. His industry experience includes IT services.\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/author\\\/hocine-mechara\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SQL Server Always On Availability Groups and Database Master Keys: A Hidden Failover Pitfall - dbi services Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server Always On Availability Groups and Database Master Keys: A Hidden Failover Pitfall","og_description":"I recently came across an interesting case involving a client whose application used SQL Server symmetric keys to encrypt sensitive data. The database was hosted in an Always On Availability Group environment for high-availability and disaster-recovery. The interesting and challenging aspect of this setup is ensuring that the encryption and decryption remains intact after a&hellip;&nbsp;","og_url":"https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/","og_site_name":"dbi services Blog","article_publisher":"https:\/\/www.facebook.com\/dbiservices\/","article_published_time":"2026-06-09T15:01:28+00:00","author":"Hocine Mechara","twitter_card":"summary_large_image","twitter_creator":"@dbiservices","twitter_site":"@dbiservices","twitter_misc":{"Written by":"Hocine Mechara","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/"},"author":{"name":"Hocine Mechara","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/dfd8f6b358f95eeca793ccffbab73eb4"},"headline":"SQL Server Always On Availability Groups and Database Master Keys: A Hidden Failover Pitfall","datePublished":"2026-06-09T15:01:28+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/"},"wordCount":975,"commentCount":0,"publisher":{"@id":"https:\/\/www.dbi-services.com\/#organization"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image.png","keywords":["data","disaster recovery","encryption","High Availability"],"articleSection":["Database","SQL Server"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/","url":"https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/","name":"SQL Server Always On Availability Groups and Database Master Keys: A Hidden Failover Pitfall - dbi services Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/#primaryimage"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/06\/image.png","datePublished":"2026-06-09T15:01:28+00:00","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-always-on-availability-groups-and-database-master-keys-a-hidden-failover-pitfall\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"SQL Server Always On Availability Groups and Database Master Keys: A Hidden Failover Pitfall"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi services Blog","description":"#BeSharing","publisher":{"@id":"https:\/\/www.dbi-services.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.dbi-services.com\/#organization","name":"dbi services","url":"https:\/\/www.dbi-services.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/09\/dbi-services-logo.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/09\/dbi-services-logo.png","width":512,"height":512,"caption":"dbi services"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/dbiservices\/","https:\/\/x.com\/dbiservices","https:\/\/www.linkedin.com\/company\/dbi-services\/","https:\/\/www.youtube.com\/user\/dbiservices"],"description":"Swiss IT consulting and services company specialized in efficient data infrastructures and platforms: databases, application servers, cloud, DevOps, digitalization, analytics, data quality and monitoring. Headquartered in Del\u00e9mont with offices in Nyon, Basel, Bern and Zurich.","email":"info@dbi-services.com","telephone":"+41 32 422 96 00","legalName":"dbi services SA"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/dfd8f6b358f95eeca793ccffbab73eb4","name":"Hocine Mechara","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2024\/01\/HME_web.jpg","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2024\/01\/HME_web.jpg","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2024\/01\/HME_web.jpg","caption":"Hocine Mechara"},"description":"Hocine Mechara has more than 5 years of experience in IT and specializes in SQL Server databases. His expertise includes installing and configuring SQL Server instances (stand-alone, Always On, FCI), migrating SQL Server databases, and operating SQL Server instances and databases, as well as Azure SQL Services and more. Hocine is a Microsoft Certified Database Administrator Associate, a Certified Administrator for SUSE Linux Enterprise Server 15, and a HashiCorp Certified Terraform Associate. He also holds a Swiss Federal Certificate of Competence as an IT Systems Engineer. Prior to joining dbi services, he worked at T-Systems Switzerland AG as a Database Engineer. His industry experience includes IT services.","url":"https:\/\/www.dbi-services.com\/blog\/author\/hocine-mechara\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/44986","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/145"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=44986"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/44986\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=44986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=44986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=44986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}