Remarque
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de vous connecter ou de modifier des répertoires.
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de modifier des répertoires.
Cet article fournit des instructions pas à pas pour vous aider à déterminer le type d’authentification utilisé lorsque vous vous connectez à Microsoft SQL Server. Vérifiez que vous exécutez les étapes sur un ordinateur client, et non sur le serveur sur lequel l’instance SQL Server que vous testez est installée. Sinon, la valeur auth_scheme dans la sortie sera toujours NTLM, même si Kerberos est configuré correctement. Cela se produit en raison d’une fonctionnalité de renforcement de la sécurité par service qui a été ajoutée dans Windows 2008. Cette fonctionnalité impose l'utilisation de NTLM pour toutes les connexions locales, même si Kerberos est disponible.
Utilisez SQL Server Management Studio
Ouvrez SQL Server Management Studio et connectez-vous à l’instance SQL Server.
Exécutez la requête suivante :
SELECT auth_scheme FROM sys.dm_exec_connections WHERE session_id = @@SPIDSinon, pour récupérer des détails de connexion supplémentaires, exécutez la requête suivante :
SELECT c.session_id, c.net_transport, c.encrypt_option, c.auth_scheme, s.host_name, @@SERVERNAME AS "remote_name", s.program_name, s.client_interface_name, s.login_name, s.nt_domain, s.nt_user_name, s.original_login_name, c.connect_time, s.login_time FROM sys.dm_exec_connections AS c JOIN sys.dm_exec_sessions AS s ON c.session_id = s.session_id WHERE c.session_id = @@SPIDConsultez la colonne auth_scheme dans les résultats pour déterminer le type d’authentification.
Utilisation de la ligne de commande
Ouvrez une invite de commande.
Exécutez la commande suivante, en remplaçant
<ServerName>par le nom de votre serveur :sqlcmd -S <ServerName> -E -Q "SELECT auth_scheme FROM sys.dm_exec_connections WHERE session_id = @@SPID"Le résultat similaire à la sortie suivante indique le type d’authentification :
auth_scheme ---------------------------------------- NTLM (1 rows affected)
Utiliser VBScript
Copiez le code VBScript suivant dans un éditeur de texte, tel que le Bloc-notes, et enregistrez-le en tant que getAuthScheme.vbs :
' Auth scheme VB script. ' Run on a client machine, not the server. ' If you run locally, you will always get NTLM even if Kerberos is properly enabled. ' ' USAGE: CSCRIPT getAuthScheme.vbs tcp:SQLProd01.contoso.com,1433 ' explicitly specify DNS suffix, protocol, and port # ('tcp' must be lower case) ' USAGE: CSCRIPT getAuthScheme.vbs SQLProd01 ' let the driver figure out the DNS suffix, protocol, and port # ' Dim cn, rs, s s = WScript.Arguments.Item(0) ' get the server name from the command-line Set cn = createobject("adodb.connection") ' ' Various connection strings depending on the driver/Provider installed on your machine ' SQLOLEDB is selected as it is on all windows machines, but may have limitations, such as lack of TLS 1.2 support ' Choose a newer provider or driver if you have it installed. ' cn.open "Provider=SQLOLEDB;Data Source=" & s & ";Initial Catalog=master;Integrated Security=SSPI" ' On all Windows machines 'cn.open "Provider=SQLNCLI11;Data Source=" & s & ";Initial Catalog=master;Integrated Security=SSPI" ' Newer 'cn.open "Provider=MSOLEDBSQL;Data Source=" & s & ";Initial Catalog=master;Integrated Security=SSPI" ' Latest, good for SQL 2012 and newer 'cn.open "Driver={ODBC Driver 17 for SQL Server};Server=" & s & ";Database=master;Trusted_Connection=Yes" ' Latest ' ' Run the query and display the results ' set rs = cn.Execute("SELECT auth_scheme FROM sys.dm_exec_connections WHERE session_id = @@SPID") WScript.Echo "Auth scheme: " & rs(0) rs.close cn.closeExécutez la commande suivante à partir de l’invite de commandes, en remplaçant
<ServerName>par le nom de votre serveur :cscript getAuthScheme.vbs <ServerName>Le résultat similaire à la sortie suivante indique le type d’authentification :
Microsoft (R) Windows Script Host Version 5.812 Copyright (C) Microsoft Corporation. All rights reserved. Auth scheme: NTLM
Utiliser Windows PowerShell
Vous pouvez utiliser Windows PowerShell pour tester le fournisseur .NET SqlClient pour essayer d’isoler le problème de votre application :
Copiez le script PowerShell suivant dans un éditeur de texte, tel que le Bloc-notes, et enregistrez-le sous le nom get-SqlAuthScheme.ps1.
#------------------------------- # # get-SqlAuthScheme.ps1 # # PowerShell script to test a System.Data.SqlClient database connection # # USAGE: # .\get-SqlAuthScheme tcp:SQLProd01.contoso.com,1433 # Explicitly specify DNS suffix, protocol, and port ('tcp' must be lowercase) # .\get-SqlAuthScheme SQLProd01 # Let the driver figure out the DNS suffix, protocol, and port # #------------------------------- # Define a parameter for the server name, defaulting to "localhost" if not provided param ([string]$server = "localhost") # Set the execution policy for the current user to Unrestricted Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser -Force # Build the connection string for the SQL Server connection $connstr = "Server=$($server);Database=master;Integrated Security=SSPI" # Create a new SQL connection object $conn = New-Object System.Data.SqlClient.SqlConnection $conn.ConnectionString = $connstr # Record the start time of the operation $start = Get-Date # Open the SQL connection $conn.Open() # Create a new SQL command object $cmd = $conn.CreateCommand() $cmd.CommandText = "SELECT auth_scheme FROM sys.dm_exec_connections WHERE session_id = @@SPID" # Query to get the authentication scheme # Execute the query and retrieve the result $dr = $cmd.ExecuteReader() $dr.Read() | Out-Null # Read the first row of the result set $auth_scheme = $dr.GetString(0) # Get the authentication scheme from the first column # Close and dispose of the SQL connection $conn.Close() $conn.Dispose() # Record the end time of the operation $end = Get-Date # Calculate the elapsed time $span = $end - $start # Output the results Write-Output "Elapsed time was $($span.TotalMilliseconds) ms." # Display the elapsed time in milliseconds Write-Output "Auth scheme for $($server): $auth_scheme" # Display the authentication scheme for the serverOuvrez Windows PowerShell, accédez au dossier contenant le script et exécutez la commande suivante :
.\get-sqlauthscheme <ServerName> # Replace "<ServerName>" with your server name.Le résultat similaire à la sortie suivante indique le type d’authentification :
Elapsed time was 0 ms. Auth scheme for <ServerName>: NTLM