簡體   English   中英

Hangfire - .net core web api - IIS 實現錯誤

[英]Hangfire - .net core web api - IIS Implementation Error

當我嘗試在 Web 服務器 IIS 上發布 Web api 時,我遇到了一個錯誤 hangfire 實現。 (WServer 2012)當我在 IIS express 上的計算機主機上啟動時,它在本地運行。 它運行良好,我在儀表板上看到了我的工作。 我在網絡服務器數據庫上使用相同的連接字符串,但它在網絡服務器上不起作用。 錯誤是這樣的;

類別:Hangfire.Processing.BackgroundExecution EventId:0

執行BackgroundServerProcess 00:00:30.0352717 仍處於Failed 狀態由於異常,將在00:00:15 內重試

異常:System.Data.SqlClient.SqlException (0x80131904):用戶“ABC SERVER”登錄失敗 在 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultAccessTokenHandling) SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)

在 ConfigureServices() 方法中;

services.AddHangfire(_ => _.UseSqlServerStorage(Configuration.GetConnectionString("HangfireDbConn"), new SqlServerStorageOptions
            {
                CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
                SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
                QueuePollInterval = TimeSpan.Zero,
                UseRecommendedIsolationLevel = true,
                UsePageLocksOnDequeue = true,
                DisableGlobalLocks = true
            }));

在 Configure() 方法中;

app.UseHangfireDashboard("/jobs");
 app.UseHangfireServer();

相同的 db 連接、本地 pc 調試模式工作正常但在 Web 服務器上發布,我從 Web 服務器收到登錄失敗錯誤有什么區別?

有什么解決方案嗎? 感謝大家的支持。

我得到了解決我的問題的方法。 實際上,我找到了我的錯誤執行點。 它是關於連接用戶授權和身份驗證信息。 在 Hangfire Sql Server 配置頁面中,我的問題有一個解決方案。 我為 Hangfire 創建了一個新用戶。 然后,為該用戶定義 auth 和 grant 操作。 之后,我從 conn 字符串中刪除了受信任的連接定義。 現在,它正在發揮作用。

CREATE USER [HangFire] WITH PASSWORD = 'strong_password_for_hangfire'
GO

IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE [name] = 'HangFire') EXEC ('CREATE SCHEMA [HangFire]')
GO

ALTER AUTHORIZATION ON SCHEMA::[HangFire] TO [HangFire]
GO

GRANT CREATE TABLE TO [HangFire]
GO

更多信息: https : //docs.hangfire.io/en/latest/configuration/using-sql-server.html

謝謝大家!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM