共用方式為


疑難排解 Microsoft Entra Connect 的 SQL 連線問題

本文說明如何疑難排解 Microsoft Entra Connect 和 SQL Server 之間的連線問題。

下列螢幕擷取畫面顯示「找不到 SQL Server」的典型錯誤。

SQL 錯誤

疑難排解步驟

使用 [以系統管理員身分執行] 和 [安裝/匯入 ADSyncTools PowerShell] 模組開啟 PowerShell 視窗。

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module ADSyncTools
Import-Module ADSyncTools
  • 顯示所有命令Get-Command *Sql* -Module ADSyncTools
  • 執行 PowerShell 函式:使用下列參數進行 Connect-ADSyncToolsSqlDatabase
    • 伺服器:SQL Server 名稱。
    • 執行個體 (選擇性):SQL Server 執行個體名稱和您想要使用的連接埠號碼 (選擇性)。 請勿指定這個參數使用預設執行個體。
    • 連接埠 (選擇性):SQL Server 埠
    • 使用者名稱 (選擇性):要連線的使用者帳戶。如果保留空白,則會使用目前登入帳戶的使用者帳戶。 若您要連線至遠端 SQL Server,此使用者名稱應是您為 Microsoft Entra Connect SQL 連線所建立的自訂服務帳戶。 Microsoft Entra Connect 會使用 Microsoft Entra Connect 同步處理服務帳戶向遠端 SQL Server 進行驗證。
    • 密碼 (選擇性):所提供 UserName 的密碼。

此 PowerShell 函式會嘗試使用傳入的認證或目前使用者的認證,繫結至指定的 SQL Server 與執行個體。 如果找不到 SQL Server,指令碼便會嘗試連線至 SQL Browser 服務,以判斷啟用的通訊協定和連接埠。

僅使用伺服器名稱的範例:


PS C:\> Connect-ADSyncToolsSqlDatabase -Server SQL1.contoso.com
Resolving server address : SQL1.contoso.com
    InterNetworkV6 : fe80::6c90:a995:3e70:ef74%17
    InterNetworkV6 : 2001:4898:e0:66:6c90:a995:3e70:ef74
    InterNetwork : 10.91.26.143

Attempting to connect to SQL1 using a TCP binding for the default instance.
   Data Source=tcp:SQL1.contoso.com\;Integrated Security=True.ConnectionString
   Successfully connected.


StatisticsEnabled                : False
AccessToken                      : 
ConnectionString                 : Data Source=tcp:SQL1\;Integrated Security=True
ConnectionTimeout                : 15
Database                         : master
DataSource                       : tcp:SQL1.contoso.com\
PacketSize                       : 8000
ClientConnectionId               : 23e06ef2-0a38-4f5f-9291-da931de40375
ServerVersion                    : 13.00.4474
State                            : Open
WorkstationId                    : SQL1
Credential                       : 
FireInfoMessageEventOnUserErrors : False
Site                             : 
Container                        : 

使用伺服器名稱和 SQL 具名執行個體的範例:


PS C:\> Connect-ADSyncToolsSqlDatabase -Server SQL1.contoso.com -Instance SQLINSTANCE1
Resolving server address : SQL1.contoso.com
   InterNetwork: 10.0.100.24 

Attempting to connect to SQL1.contoso.com\SQLINSTANCE1 using a TCP binding.
   Data Source=tcp:SQL1.contoso.com\SQLINSTANCE1;Integrated Security=True
   Successfully connected.


StatisticsEnabled                : False
AccessToken                      : 
ConnectionString                 : Data Source=tcp:SQL1.contoso.com\SQLINSTANCE1;Integrated Security=True
ConnectionTimeout                : 15
Database                         : master
DataSource                       : tcp:SQL1.contoso.com\SQLINSTANCE1
PacketSize                       : 8000
ClientConnectionId               : 2b365b7a-4348-45f6-9314-d6b56db36dbd
ServerVersion                    : 13.00.4259
State                            : Open
WorkstationId                    : SQL1
Credential                       : 
FireInfoMessageEventOnUserErrors : False
Site                             : 
Container                        : 


使用無法連線到的 SQL 執行個體範例。 其會嘗試查詢 SQL Server Browser 服務,並顯示可用的 SQL 執行個體和個別埠。


PS C:\> Connect-ADSyncToolsSqlDatabase -Server SQL01.Contoso.com -Instance DEFAULT
Resolving server address : SQL01.Contoso.com
   InterNetwork: 10.0.100.24 

Attempting to connect to SQL01.Contoso.com\SQL using a TCP binding.
   Data Source=tcp:SQL01.Contoso.com\SQL;Integrated Security=True
Connect-ADSyncToolsSqlDatabase : Unable to connect using a TCP binding.  A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was 
not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance 
Specified) 
At line:1 char:1
+ Connect-ADSyncToolsSqlDatabase -Server SQL01.Contoso.com -Insta ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ConnectionError: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Connect-ADSyncToolsSqlDatabase
 
TROUBLESHOOTING: Attempting to query the SQL Server Browser service configuration on SQL01.Contoso.com. 

SQL browser response contained 2 instances.
Verifying protocol bindings and port connectivity...
SQLINSTANCE1    : Enabled - port 49823 is assigned and reachable through the firewall
SQL2019         : Enabled - port 50631 is assigned and reachable through the firewall

WHAT TO TRY NEXT: 

Each SQL instance must be bound to an explicit static TCP port and paired with an inbound firewall rule on SQL01.Contoso.com to allow connection. Review the TcpStatus field for each instance and take cor
rective action. 


InstanceName : SQLINSTANCE1
tcp          : 49823
TcpStatus    : Enabled - port 49823 is assigned and reachable through the firewall

InstanceName : SQL2019
tcp          : 50631
TcpStatus    : Enabled - port 50631 is assigned and reachable through the firewall


後續步驟