【问题标题】:Error while connecting Azure Data Studio working with Docker in a container with SQL Server连接 Azure Data Studio 时出错,在容器中使用 Docker 与 SQL Server
【发布时间】:2023-02-02 15:08:18
【问题描述】:

我在通过 Azure Data Studio 连接 SQL Server 时遇到问题。 我正在尝试在 MacBook Air M1 - Ventura 13.0.1 上进行连接 我在这里看到了常见的问题,但我没有得到解决方案。欢迎任何形式的帮助。

我得到的错误是

Microsoft.Data.SqlClient.SqlException (0x80131904): 已成功与服务器建立连接,但在预登录握手期间发生错误。 (提供者:TCP 提供者,错误:35 - 捕获到内部异常) ---> System.Security.Authentication.AuthenticationException:远程证书被提供的 RemoteCertificateValidationCallback 拒绝。 在 System.Net.Security.SslStream.SendAuthResetSignal(ProtocolToken 消息,ExceptionDispatchInfo 异常) 在 System.Net.Security.SslStream.CompleteHandshake(SslAuthenticationOptions sslAuthenticationOptions) 在 System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](Boolean receiveFirst,Byte[] reAuthenticationData,CancellationToken cancellationToken) 在 System.Net.Security.SslStream.AuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions) 在 Microsoft.Data.SqlClient.SNI.SNITTCPHandle.EnableSsl(UInt32 选项) 在 Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException 异常,布尔 breakConnection,Action1 wrapCloseInAction) at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at Microsoft.Data.SqlClient.TdsParser.EnableSsl(UInt32 info, SqlConnectionEncryptOption encrypt, Boolean integratedSecurity) at Microsoft.Data.SqlClient.TdsParser.ConsumePreLoginHandshake(SqlConnectionEncryptOption encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean& marsCapable, Boolean& fedAuthRequired, Boolean tlsFirst) at Microsoft.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnectionString connectionOptions, Boolean withFailover) at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken, DbConnectionPool pool) at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at Microsoft.Data.ProviderBase.DbConnectionPool.WaitForPendingOpen() --- End of stack trace from previous location --- at Dapper.SqlMapper.QueryAsync[T](IDbConnection cnn, Type effectiveType, CommandDefinition command) in /_/Dapper/SqlMapper.Async.cs:line 417 at Application.Repository.EmployeeRepository.GetAllEmployeesAsync() in /Users/ddxkalin/Dev/ProdSys/Application/Repository/EmployeeRepository.cs:line 21 at API.Controllers.EmployeesController.GetAllEmployeesAsync() in /Users/ddxkalin/Dev/ProdSys/API/Controllers/EmployeesController.cs:line 18 at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask1 actionResultValueTask) 在 Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker 调用程序、任务 lastTask、接下来的状态、范围范围、对象状态、布尔值已完成) 在 Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed 上下文) 在 Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next、Scope& scope、Object& state、Boolean& isCompleted) 在 Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker 调用程序、任务 lastTask、接下来的状态、范围范围、对象状态、布尔值已完成) 在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|20_0(ResourceInvoker 调用程序、任务 lastTask、接下来的状态、范围范围、对象状态、布尔值已完成) 在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker 调用程序、任务任务、IDisposable 范围) 在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker 调用程序、任务任务、IDisposable 范围) 在 Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(端点端点、任务请求任务、ILogger 记录器) 在 Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext 上下文) 在 Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext) 在 Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext,ISwaggerProvider swaggerProvider) 在 Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext 上下文) 在 Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext 上下文) ClientConnectionId:da9520c9-1356-49ad-add6-0ed52ee9937b 错误号:-2146893019,状态:0,等级:20

在 appsettings.json 中,connectionString 是

    "SqlConnection": "server=localhost;database=ProdSysDB;User Id=sa;Password=Admin123@;Integrated Security=true;"

这是连接的 Azure Data Studio 中的连接详细信息

【问题讨论】:

  • 撇开...选择一种身份验证方法并坚持使用。 Integrated Security=true; 表示使用当前进程的 Windows/Active Directory/Kerberos 身份验证令牌。 User Id=...;Password=...; 表示使用 SQL 登录凭据。
  • 鉴于错误消息是AuthenticationException: The remote certificate was rejected by the provided RemoteCertificateValidationCallback,您是否注意到您在 ADS 连接窗口中选择了Trust Server Certificate: true?你认为这两者可能有关联吗?您是否尝试过将 Trust Server Certificate=true; 添加到您的连接字符串中?参考:SqlConnectionStringBuilder.TrustServerCertificate Property
  • @AlwaysLearning 是的,问题出在集成安全性上,当我删除它并添加 TrustServerCetificate=true 时,一切正常!非常感谢!!!
  • @AlwaysLearning 由于您的评论解决了问题,请将其作为答案发布以帮助其他社区成员。

标签: c# .net sql-server azure asp.net-core


【解决方案1】:

正如 AlwaysLearning 在 cmets 中建议的那样,将其发布为帮助其他社区成员的答案。

连接字符串中的实例名称与预期的实例名称不兼容,这可能是 The remote certificate was rejected by the provided RemoteCertificateValidationCallback 的原因。

使用Trust Server Certificate作为true,当您在连接字符串中使用TrustServerCertificate=true(或其等价物)时,连接过程将跳过信任链验证。

  • 因为integrated security更多的是一个Windows特性,所以你必须有windows认证。

  • 综合安全是用户认证的类型。真对应于“Windows 身份验证”,而 False 对应于“SQL 服务器身份验证”;

【讨论】:

    猜你喜欢
    • 2019-08-23
    • 2019-10-27
    • 2020-07-29
    • 1970-01-01
    • 2021-09-09
    • 2022-01-25
    • 2019-04-08
    • 2017-06-07
    • 2021-10-19
    相关资源
    最近更新 更多