Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

ConnectionFailureException when user running the command does not match the ConnectAsUserName

未關閉
#186 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
需要釐清
活躍度
停滯
技術堆疊
csharp, powershell, sql
領域
databases

研究方向

從提供的 PowerShell 重現步驟以及堆疊追蹤中的 ConnectionManager.InternalConnect 和 SqlConnection.Open 路徑開始。檢查當 ConnectAsUser 與呼叫端不同時,SqlServer 22.3.0 的相依性集合如何載入,尤其是缺少的 System.Diagnostics.StackTrace 組件。只要相同的 script 能成功連線,或能清楚識別底層相依性問題,即可視為完成。

由索引模型根據 Issue 內容生成。

描述

$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
主要語言
C#
星號
143
分支
29
PR 合併指標
30 天內沒有已合併 PR

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

microsoft/sqlmanagementobjects 的其他 Issue

查看 microsoft/sqlmanagementobjects 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。