microsoft / SQLServerPSModule

This repo is the home of SQL Server PowerShell Module development.
MIT License
51 stars 1 forks source link

invoke-Sqlcmd : Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder #89

Open pradeep14316 opened 3 months ago

pradeep14316 commented 3 months ago

Haven't started on reproducing outside of Azure Pipelines yet, but: Copied from the issue in Description SqlServer 22.0.59 / Windows PowerShell 5.1 / windows-latest/ Azure DevOps

This occurs on Microsoft-hosted agents.

When attempting to connect to a Azure SQL Databases with Active Directory Password authentication, this occurs:

with the following connection string characteristics: MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Authentication="Active Directory Password";

2024-07-16T13:14:17.1472821Z ##[debug]Invoke-Sqlcmd : Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder Microsoft.Identity.Client.PublicClientApplicationBuilder.WithParentActivityOrWindow(System.Func1<System.Windows.Forms.IWin32Window>)'. 2024-07-16T13:14:17.1485055Z ##[debug]At D:\a\_temp\1ded7a10-b4d6-402d-8b7a-38aa2208e1c4.ps1:54 char:1 2024-07-16T13:14:17.1498800Z ##[debug]+ Invoke-Sqlcmd -Query "$SCHEMAQuery" -ConnectionString "Server=tcp:azr ... 2024-07-16T13:14:17.1510324Z ##[debug]+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2024-07-16T13:14:17.1523235Z ##[debug] + CategoryInfo : InvalidOperation: (:) [Invoke-Sqlcmd], SqlException 2024-07-16T13:14:17.1534509Z ##[debug] + FullyQualifiedErrorId : SqlExceptionError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand 2024-07-16T13:14:17.1546662Z ##[debug] 2024-07-16T13:14:17.1564682Z ##[debug]Script stack trace: 2024-07-16T13:14:17.1598572Z ##[debug]at <ScriptBlock>, D:\a\_temp\1ded7a10-b4d6-402d-8b7a-38aa2208e1c4.ps1: line 54 2024-07-16T13:14:17.1609725Z ##[debug]at <ScriptBlock>, D:\a\_temp\1ded7a10-b4d6-402d-8b7a-38aa2208e1c4.ps1: line 52 2024-07-16T13:14:17.1621003Z ##[debug]at <ScriptBlock>, <No file>: line 1 2024-07-16T13:14:17.1638556Z ##[debug]Exception: 2024-07-16T13:14:17.2213587Z ##[debug]Microsoft.Data.SqlClient.SqlException (0x80131904): Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder Microsoft.Identity.Client.PublicClientApplicationBuilder.WithParentActivityOrWindow(System.Func1)'. ---> System.MissingMethodException: Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder Microsoft.Identity.Client.PublicClientApplicationBuilder.WithParentActivityOrWindow(System.Func1<System.Windows.Forms.IWin32Window>)'. 2024-07-16T13:14:17.2227297Z ##[debug] at Microsoft.Data.SqlClient.ActiveDirectoryAuthenticationProvider.CreateClientAppInstance(PublicClientAppKey publicClientAppKey) 2024-07-16T13:14:17.2240879Z ##[debug] at Microsoft.Data.SqlClient.ActiveDirectoryAuthenticationProvider.GetPublicClientAppInstance(PublicClientAppKey publicClientAppKey) 2024-07-16T13:14:17.2253692Z ##[debug] at Microsoft.Data.SqlClient.ActiveDirectoryAuthenticationProvider.<AcquireTokenAsync>d__21.MoveNext() 2024-07-16T13:14:17.2266251Z ##[debug]--- End of stack trace from previous location where exception was thrown --- 2024-07-16T13:14:17.2278401Z ##[debug] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 2024-07-16T13:14:17.2289859Z ##[debug] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 2024-07-16T13:14:17.2301125Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.<>c__DisplayClass159_1.<<GetFedAuthToken>b__3>d.MoveNext() 2024-07-16T13:14:17.2312170Z ##[debug]--- End of stack trace from previous location where exception was thrown --- 2024-07-16T13:14:17.2323421Z ##[debug] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 2024-07-16T13:14:17.2334444Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.GetFedAuthToken(SqlFedAuthInfo fedAuthInfo) 2024-07-16T13:14:17.2345596Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.GetFedAuthToken(SqlFedAuthInfo fedAuthInfo) 2024-07-16T13:14:17.2356604Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OnFedAuthInfo(SqlFedAuthInfo fedAuthInfo) 2024-07-16T13:14:17.2367914Z ##[debug] at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) 2024-07-16T13:14:17.2379114Z ##[debug] at Microsoft.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) 2024-07-16T13:14:17.2390099Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) 2024-07-16T13:14:17.2401214Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover, Boolean isFirstTransparentAttempt, Boolean disableTnir) 2024-07-16T13:14:17.2412520Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) 2024-07-16T13:14:17.2423532Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) 2024-07-16T13:14:17.2435199Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, ServerCertificateValidationCallback serverCallback, ClientCertificateRetrievalCallback clientCallback, DbConnectionPool pool, String accessToken, SqlClientOriginalNetworkAddressInfo originalNetworkAddressInfo, Boolean applyTransientFaultHandling) 2024-07-16T13:14:17.2445782Z ##[debug] at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) 2024-07-16T13:14:17.2457167Z ##[debug] at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) 2024-07-16T13:14:17.2468002Z ##[debug] at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) 2024-07-16T13:14:17.2479137Z ##[debug] at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) 2024-07-16T13:14:17.2490177Z ##[debug] at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) 2024-07-16T13:14:17.2501432Z ##[debug] at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) 2024-07-16T13:14:17.2512612Z ##[debug] at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) 2024-07-16T13:14:17.2523755Z ##[debug] at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) 2024-07-16T13:14:17.2534590Z ##[debug] at Microsoft.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) 2024-07-16T13:14:17.2545970Z ##[debug] at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry, SqlConnectionOverrides overrides) 2024-07-16T13:14:17.2556865Z ##[debug] at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides) 2024-07-16T13:14:17.2567976Z ##[debug] at Microsoft.SqlServer.Management.PowerShell.ExecutionProcessor.ExecuteBatch(String batch) 2024-07-16T13:14:17.2578956Z ##[debug] at Microsoft.SqlServer.Management.PowerShell.ExecutionProcessor.ProcessBatch(String str, Int32 num) 2024-07-16T13:14:17.2672372Z ##[error]Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder Microsoft.Identity.Client.PublicClientApplicationBuilder.WithParentActivityOrWindow(System.Func1<System.Windows.Forms.IWin32Window>)'. 2024-07-16T13:14:17.2673635Z ##[debug]Processed: ##vso[task.logissue source=TaskInternal;type=error]Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder Microsoft.Identity.Client.PublicClientApplicationBuilder.WithParentActivityOrWindow(System.Func1)'. 2024-07-16T13:14:17.3068582Z ##[debug]Exit code: 1 2024-07-16T13:14:17.3106125Z ##[debug]Leaving Invoke-VstsTool. 2024-07-16T13:14:17.3704800Z ##[error]PowerShell exited with code '1'. 2024-07-16T13:14:17.3705621Z ##[debug]Processed: ##vso[task.logissue source=TaskInternal;type=error]PowerShell exited with code '1'. 2024-07-16T13:14:17.3774197Z ##[debug]Processed: ##vso[task.complete result=Failed]Error detected 2024-07-16T13:14:17.3846711Z ##[debug]Loading module from path 'D:\a_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\5.242.0\psmodules\VstsAzureHelpers\VstsAzureHelpers_.psm1'. 2024-07-16T13:14:17.3978576Z ##[debug]$OVERRIDING $global:DebugPreference from 'Continue' to 'SilentlyContinue'. 2024-07-16T13:14:17.4005738Z ##[debug]Loading resource strings from: D:\a_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\5.242.0\psmodules\VstsAzureHelpers/module.json 2024-07-16T13:14:17.4371588Z ##[debug]Loaded 19 strings. 2024-07-16T13:14:17.4403007Z ##[debug]SYSTEM_CULTURE: 'en-US' 2024-07-16T13:14:17.4426060Z ##[debug]Loading resource strings from: D:\a_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\5.242.0\psmodules\VstsAzureHelpers\Strings\resources.resjson\en-US\resources.resjson 2024-07-16T13:14:17.4798357Z ##[debug]Loaded 19 strings.

DesiStuff commented 3 months ago

having the same issue, did you find any solution?