簡體   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