I'm trying to connect to SQL Server Express in my Hangfire service
.
Code in my Startup.cs
looks like this:
services.AddHangfire(configuration => configuration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseSqlServerStorage(Configuration.GetConnectionString("HangfireConnection"), new SqlServerStorageOptions
{
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
QueuePollInterval = TimeSpan.Zero,
UseRecommendedIsolationLevel = true,
UsePageLocksOnDequeue = true,
DisableGlobalLocks = true
}));
services.AddHangfireServer();
Based on documentation, Hangfire 1.7 have built ib sql query
to create database.
I make default connection string from docs:
"HangfireConnection": "Server=.\\sqlexpress; Database=Hangfire; Integrated Security=SSPI;"
But when I run my app, I get this error:
System.Data.SqlClient.SqlException: 'Cannot open database "Hangfire" requested by the login. The login failed.
Login failed for user 'DESKTOP-FOVJ16Q\Michal'
My Security
tab from SQL Server Express looks like this:
Could you tell me, what can I check to make connection with my SQL Server Express?
EDIT1
My SQL Server Express "Security" tab with Logins
:
My DESKTOP-FOVJ16Q\Micha
properties:
EDIT2
I checked for now, from that connection string:
"Server=.\\SQLEXPRESS;Database=TaskManager;Trusted_Connection=True;"
I can simply make database in my SQL Express
and look on it in Management studio
If you read the comments on that page you linked to (https://docs.hangfire.io/en/latest/configuration/using-sql-server.html), you'll find a question by "Fabian Schneiter" who asks pretty much the same question as you did - and got this response:
You need to create the database
Hangfire
on your server first.. I understood, that hangfire will create the DB too, but that's wrong. If you have a Hangfire DB, Hangfire will create all needed tables..
So my recommendation: try creating the Hangfire
database as a new database - then run your code again and see if it works