Home > Net >  Using SQL Server with dotnet core 6.0 in a Windows Service
Using SQL Server with dotnet core 6.0 in a Windows Service

Time:09-13

I am trying to add SQL Server connections to a new Windows Service. All the documentation indicates that we add

builder.Services.AddDbContext<ApplicationContext> 

in Program.cs.

However a Windows service (IHost) does not show the AddDbContext method in services. Does anyone have any experience with this?

Already been here: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-6.0&tabs=visual-studio

and here: https://jasonwatmore.com/post/2022/03/18/net-6-connect-to-sql-server-with-entity-framework-core @JasonWatmore

and similar....

CodePudding user response:

You should use AddDbContext instead of AddDbContact. Try it; services.AddDbContext<ApplicationContext>();

CodePudding user response:

You are adding the wrong dependency. You need to add this dependency

builder.Services.AddDbContext<ApplicationDbContext>(options =>
        options.UseSqlServer(connectionString));
  • Related