繁体   English   中英

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

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

我在我的 Windows 机器上从 Visual Studio 2017 制作了一个.NET Core 2.2 应用程序,并尝试将它托管在运行 RHEL 7 服务器的 Linux 机器上。 我正在尝试使用应用程序中的ADO.NET通过 SqlPassword 身份验证(我有用户 ID 和密码)连接到SQL Server DB

当我这样做时,我经常遇到异常。 我在这里观察到的问题:

消息:无法使用 Kerberos 进行身份验证。 确保已使用“kinit”在客户端上初始化 Kerberos,并且已为 SQL Server 注册服务主体名称以允许 Kerberos 身份验证。 ErrorCode=InternalError,Exception=Interop+NetSecurityNative+GssApiException:GSSAPI 操作失败,错误 - 提供了无效的状态代码(SPNEGO 找不到协商机制)。 在 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, 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, 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 重试) 在 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

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

我必须安装任何其他软件包吗? 还是与代理有关? 我在互联网上搜索了很多,但没有运气。 请在这方面帮助我。

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

提前致谢... :)

默认情况下,SQL 会尝试 Windows 登录(您知道世界会围绕窗口旋转!)即使它是 SQL 登录,尽管您说不可信,但它还是会尝试,因此在 Windows 服务器上,这通常在后台悄悄发生,因为您已经拥有一张 kerberos 票。 但是,由于这是 linux,需要特别说明您不会使用任何基于 Windows 的登录,这是通过“Integrated Security=False”完成的。

暂无
暂无

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

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