microsoft / microsoft/sqlmanagementobjects

ConnectionFailureException when user running the command does not match the ConnectAsUserName

Abierto
#186 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
C#
Estrellas
143
Forks
28
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

$Credential = Get-Credential -Message "Enter your login name" 
Import-Module -Name SqlServer
$ServerInstance = "SERVERNAME"
$Server = New-Object Microsoft.SqlServer.Management.Smo.Server $ServerInstance
$Server.ConnectionContext.LoginSecure = $true
$Server.ConnectionContext.ConnectAsUser = $true
$Server.ConnectionContext.ConnectAsUserName = $Credential.GetNetworkCredential().UserName
$Server.ConnectionContext.ConnectAsUserPassword = $Credential.GetNetworkCredential().Password
try {$Server.ConnectionContext.Connect()} catch {$_.Exception | Format-List -Force}

Throws the following error, when the user running the command does not match the ConnectAsUserName

ErrorRecord                 : Exception calling "Connect" with "0" argument(s): "Failed to connect to server SERVERNAME."
WasThrownFromThrowStatement : False
TargetSite                  : Void CheckActionPreference(System.Management.Automation.Language.FunctionContext, System.Exception)
Message                     : Exception calling "Connect" with "0" argument(s): "Failed to connect to server SERVERNAME."
Data                        : {[System.Management.Automation.Interpreter.InterpretedFrameInfo, System.Management.Automation.Interpreter.InterpretedFrameInfo[]]}
InnerException              : Microsoft.SqlServer.Management.Common.ConnectionFailureException: Failed to connect to server SERVERNAME.
                               ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Diagnostics.StackTrace, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The
                              system cannot find the file specified.
                              File name: 'System.Diagnostics.StackTrace, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
                                 at Microsoft.Data.SqlClient.SqlConfigurableRetryLogicManager.get_ConnectionProvider()
                                 at Microsoft.Data.SqlClient.SqlConnection.get_RetryLogicProvider()
                                 at Microsoft.Data.SqlClient.SqlConnection.get_IsProviderRetriable()
                                 at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides)
                                 at Microsoft.Data.SqlClient.SqlConnection.Open()
                                 at Microsoft.SqlServer.Management.Common.ConnectionManager.InternalConnectImpl()
                                 at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
                              --- End of stack trace from previous location ---
                                 at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
                                 at System.Security.Principal.WindowsIdentity.RunImpersonatedInternal(SafeAccessTokenHandle token, Action action)
                                 at Microsoft.SqlServer.Management.Common.ConnectionManager.InternalConnect()
                                 at Microsoft.SqlServer.Management.Common.ConnectionManager.Connect()
                                 --- End of inner exception stack trace ---
                                 at Microsoft.SqlServer.Management.Common.ConnectionManager.Connect()
                                 at CallSite.Target(Closure, CallSite, Object)
HelpLink                    :
Source                      : System.Management.Automation
HResult                     : -2146233087
StackTrace                  :    at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
                                 at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
                                 at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
                                 at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

Running Windows 11,

Name                           Version          Source                           ProviderName
----                           -------          ------                           ------------
SqlServer                      22.3.0           https://www.powershellgallery.c… PowerShellGet

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con la reproducción proporcionada en PowerShell y las rutas ConnectionManager.InternalConnect y SqlConnection.Open del stack trace. Comprueba cómo se carga el conjunto de dependencias de SqlServer 22.3.0 cuando ConnectAsUser difiere del llamador, especialmente la ausencia del ensamblado System.Diagnostics.StackTrace. Se considera terminado cuando el mismo script se conecta correctamente o se identifica claramente el problema de dependencias subyacente.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
csharp, powershell, sql
Área
databases
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.