How to fix Error 9793 on Windows Server 2025 / Windows 11

Troubleshooting Guide: Error 9793 – “The Target Service Name Could Not Be Found” in SQL Server 2025

Why This Error Happens

Error 9793 occurs when SQL Server’s Database Mirroring or Always On Availability Groups endpoint cannot resolve the Service Principal Name (SPN) or endpoint listener associated with the target instance, typically due to a mismatch in the mirroring/AG endpoint URL syntax. This is often caused by an incorrect TCP://<servername>:<port> format in the connection string, a firewall blocking the mirroring endpoint port, or the endpoint being stopped/disabled on the partner server. In Kerberos-authenticated environments, this can also stem from missing or duplicate SPNs in Active Directory, preventing the service from being located via routing information.

Step-by-Step Resolution Guide

Step 1: Verify the Endpoint URL Syntax

  • Open SQL Server Management Studio (SSMS) and connect to both the primary and secondary replicas.
  • Run SELECT name, role_desc, state_desc, connection_auth_desc, type_desc FROM sys.database_mirroring_endpoints; on both instances.
  • Confirm the endpoint state_desc shows STARTED. If it shows STOPPED, run ALTER ENDPOINT [EndpointName] STATE = STARTED;.
  • Double-check that the connection string used in ALTER DATABASE... SET PARTNER or the AG listener uses the exact format TCP://FQDN:PortNumber (e.g., TCP://SQLNODE01.contoso.com:5022).

Step 2: Check Firewall and Port Accessibility on Windows Server 2025

  • Ensure the mirroring/AG endpoint port (commonly 5022 or 5023) is open on both the primary and secondary nodes.
  • Open PowerShell as Administrator and test connectivity:
  Test-NetConnection -ComputerName SQLNODE02.contoso.com -Port 5022
  • If blocked, create an inbound rule via Windows Defender Firewall with Advanced Security, or run:
  New-NetFirewallRule -DisplayName "SQL Mirroring Endpoint" -Direction Inbound -Protocol TCP -LocalPort 5022 -Action Allow
  • Verify no third-party antivirus or network security groups (in Azure/VM scenarios) are silently dropping the traffic.

Step 3: Validate Service Principal Names (SPNs) in Active Directory

  • Open Command Prompt as a Domain Admin and list existing SPNs for the SQL Server service account:
  setspn -L DOMAIN\SQLServiceAccount
  • Confirm an SPN exists in the format MSSQLSvc/SQLNODE01.contoso.com:1433 (or the relevant port).
  • If missing, register it manually:
  setspn -S MSSQLSvc/SQLNODE01.contoso.com:1433 DOMAIN\SQLServiceAccount
  • Restart the SQL Server service on both nodes to refresh Kerberos ticket registration.

Step 4: Re-establish the Mirroring or Availability Group Session

  • On the primary replica, re-run the partner configuration command to force SQL Server to re-resolve the endpoint:
  ALTER DATABASE [YourDB] SET PARTNER = 'TCP://SQLNODE02.contoso.com:5022';
  • If using Always On Availability Groups, remove and re-add the replica via SSMS under Always On High Availability > Availability Group Listeners.
  • Monitor the SQL Server Error Log and Windows Event Viewer (Application log) for confirmation that the session synchronized successfully.

Alternative or Verification Steps

  • Run SELECT * FROM sys.dm_db_mirroring_connections; to confirm an active, authenticated connection now exists between partners with no error state.
  • If the issue persists, temporarily disable Kerberos and force NTLM authentication on the endpoint (ALTER ENDPOINT... AUTHENTICATION = WINDOWS NTLM) to isolate whether the root cause is SPN-related versus a network/firewall issue.