Hangfire - .net core web api - IIS Implementation Error

-2

I got an error hangfire implementation when I try to publish the web api on web server IIS. (WServer 2012) It was work on locally when I start on my computer host on IIS express. It was working well, I see my jobs on dashboard. I use the same connection strings on web server db, but it wasn't work on web server. The error is like that;

Category: Hangfire.Processing.BackgroundExecution EventId: 0

Execution BackgroundServerProcess is still in the Failed state for 00:00:30.0352717 due to an exception, will be retried no more than in 00:00:15

Exception: System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'ABC SERVER'. 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)

In ConfigureServices() method;

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
            }));

In Configure() method;

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

What is the difference between same db connection, local pc debug mode works fine but publishing on web server, I got an login failed error from web server ?

Is there any solutions for that ? Thanks for all supports.

c#
sql-server
asp.net-core-webapi
hangfire
hangfire-sql
asked on Stack Overflow Feb 10, 2020 by isoguzay • edited Feb 10, 2020 by isoguzay

1 Answer

0

I got a solution for my problem. Actually, I find my mistake point of implementation. It is about the connection user grant and auth informations. In Hangfire Sql Server config page has a solution for my problem. I create a new user for Hangfire. Then, define the auth and grant operations for this user. After that, I delete trusted connection definition from my conn string. Now, it is working.

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

For more : https://docs.hangfire.io/en/latest/configuration/using-sql-server.html

Thanks for everyone!

answered on Stack Overflow Feb 10, 2020 by isoguzay

User contributions licensed under CC BY-SA 3.0