简体   繁体   English

无法从 RHEL 7 上的 .Net 核心应用程序连接到 SQL Server 数据库

[英]Not able to connect to a SQL Server db from .Net core app on RHEL 7

I have made a .NET Core 2.2 application from Visual Studio 2017 on my Windows machine and tried to host it on a Linux machine running RHEL 7 Server.我在我的 Windows 机器上从 Visual Studio 2017 制作了一个.NET Core 2.2 应用程序,并尝试将它托管在运行 RHEL 7 服务器的 Linux 机器上。 I am trying to connect to a SQL Server DB with SqlPassword authentication (I am having a user id and password) using ADO.NET from the application.我正在尝试使用应用程序中的ADO.NET通过 SqlPassword 身份验证(我有用户 ID 和密码)连接到SQL Server DB

I am constantly getting an exception when I am doing this.当我这样做时,我经常遇到异常。 The issue that I have observed here:我在这里观察到的问题:

Message: Cannot authenticate using Kerberos.消息:无法使用 Kerberos 进行身份验证。 Ensure Kerberos has been initialized on the client with 'kinit' and a Service Principal Name has been registered for the SQL Server to allow Kerberos authentication.确保已使用“kinit”在客户端上初始化 Kerberos,并且已为 SQL Server 注册服务主体名称以允许 Kerberos 身份验证。 ErrorCode=InternalError, Exception=Interop+NetSecurityNative+GssApiException: GSSAPI operation failed with error - An invalid status code was supplied (SPNEGO cannot find mechanisms to negotiate). ErrorCode=InternalError,Exception=Interop+NetSecurityNative+GssApiException:GSSAPI 操作失败,错误 - 提供了无效的状态代码(SPNEGO 找不到协商机制)。 at System.Net.Security.NegotiateStreamPal.GssInitSecurityContext(SafeGssContextHandle& context, SafeGssCredHandle credential, Boolean isNtlm, SafeGssNameHandle targetName, GssFlags inFlags, Byte[] buffer, Byte[]& outputBuffer, UInt32& outFlags, Int32& isNtlmUsed) at System.Net.Security.NegotiateStreamPal.EstablishSecurityContext(SafeFreeNegoCredentials credential, SafeDeleteContext& context, String targetName, ContextFlagsPal inFlags, SecurityBuffer inputBuffer, SecurityBuffer outputBuffer, ContextFlagsPal& outFlags) at System.Data.SqlClient.SNI.SNIProxy.GenSspiClientContext(SspiClientContextStatus sspiClientContextStatus, Byte[] receivedBuff, Byte[]& sendBuff, Byte[] serverName) at System.Data.SqlClient.SNI.TdsParserStateObjectManaged.GenerateSspiClientContext(Byte[] receivedBuff, UInt32 receivedLength, Byte[]& sendBuff, UInt32& sendLength, Byte[] _sniSpnBuffer) at System.Data.SqlClient.TdsParser.SNISSPIData(Byte[] receivedBuff, UInt32 receivedLength, Byte[]& sendBuff, UInt32& sendLen在 System.Net.Security.NegotiateStreamPal.GssInitSecurityContext(SafeGssContextHandle& context, SafeGssCredHandle credential, Boolean isNtlm, SafeGssNameHandle targetName, GssFlags inFlags, Byte[] buffer, Byte[]& outputBuffer, UInt32& outFlags, Int32& isNt. NegotiateStreamPal.EstablishSecurityContext(SafeFreeNegoCredentials 凭证,SafeDeleteContext& 上下文,字符串 targetName,ContextFlagsPal inFlags,SecurityBuffer inputBuffer,SecurityBuffer outputBuffer,ContextFlagsPal& outFlags) 在 System.Data.SqlClient.SNI.SNIProxy.GenSspiClientContext(SspiClientContextStatus],BytespiClientContext(SspiClientContextStatus],BytespiClientContext(SspiClientContextStatus) sendBuff, Byte[] serverName) 在 System.Data.SqlClient.SNI.TdsParserStateObjectManaged.GenerateSspiClientContext(Byte[] receivedBuff, UInt32 receivedLength, Byte[]& sendBuff, UInt32& sendLength, Byte[] _sniSpnBuffer) 在 System.Data.SqlClient.TdsParser .SNISSSPIData(Byte[] receivedBuff, UInt32 receivedLength, Byte[]& sendBuff, UInt32& sendLen gth), StackTrace: at System.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) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInterna gth), StackTrace: at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, StringFault and Boolean apply)在 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) 在 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions) poolKey, DbConnectionOptions userOptions) 在 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInterna l oldConnection) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSour l oldConnection) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Dternal BooleanConnection onlyOneOptions, DbConnectionOptionIn连接)在 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource 1 retry, DbConnectionOptions, DbConnectionOptions userInOptions DbConnectionInternal& connection) 在 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection externalConnection, DbConnectionFactory connectionFactory, TaskCompletionSour ce 1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource 1 retry) at System.Data.SqlClient.SqlConnection.Open() at MobileMetrics.Services.QueryExecutionDAL.SqlDbToolkit.GetData(IList 1 dBQueries, IList 1 columnDetails) in D:__MM_VNext\\Middleware\\Main\\Source\\MobileMetrics.Services\\DbToolkit\\DbToolkits\\SqlDbToolkit.cs:line 172 ce 1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource 1 重试) 在 System.Data.SqlClient.SqlConnection.Open() 在 MobileMetrics.Services.QueryExecutionDAL.SqlDbToolkit.GetData(IList 1 dBQueries, IList 1 columnDetails) 在 D:__MM_VNext\\Middleware\\Main\\Source\\MobileMetrics.Services\\DbToolkit\\DbToolkits\\SqlDbToolkit.cs:line 172

My connection string used is: Data Source=my-server;Initial Catalog=my-db;UserId=testuser;Password=user@123;Trusted_Connection=False;MultipleActiveResultSets=true我使用的连接字符串是: Data Source=my-server;Initial Catalog=my-db;UserId=testuser;Password=user@123;Trusted_Connection=False;MultipleActiveResultSets=true

Do I have to install any other package?我必须安装任何其他软件包吗? Or is it something related to a proxy?还是与代理有关? I have searched a lot in the Internet but there is no luck.我在互联网上搜索了很多,但没有运气。 Please help me in this regard.请在这方面帮助我。

The details are as follows: Host: Linux (RHEL 7) .NET Core: v2.2 Database: SQL Server 2012 Developer Edition IDE: Visual Studio 2017 on Windows 7详细信息如下:主机: Linux (RHEL 7) .NET Core: v2.2数据库: SQL Server 2012 Developer Edition IDE: Windows 7 上的 Visual Studio 2017

Thanks in advance... :)提前致谢... :)

SQL by default tries windows logins (you knew the world rotated round windows!) even when its an SQL login, despite you saying not trusted, it tries anyway, so on a windows server this often quietly happens in the background, because you already have a kerberos ticket.默认情况下,SQL 会尝试 Windows 登录(您知道世界会围绕窗口旋转!)即使它是 SQL 登录,尽管您说不可信,但它还是会尝试,因此在 Windows 服务器上,这通常在后台悄悄发生,因为您已经拥有一张 kerberos 票。 However, as this is linux, it needs to be told specifically you will not be using any windows based logins, this is done via "Integrated Security=False".但是,由于这是 linux,需要特别说明您不会使用任何基于 Windows 的登录,这是通过“Integrated Security=False”完成的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM