1
votes

I am trying to published my .Net Core app to IIS that uses Entity Framework. I can publish it fine but no database is included in the publish wizard.

I have followed different tutorials including this: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.0

However none tell you how to deploy your database or what needs to be done if using entity framework. I'm relatively new to published and hosting web apps so I'm not sure what to do.

At the moment my frontend of the web app loads on IIS but when I go to login it brings up a 500 error. I have included my connection string and added a user and gve correct permissions under SSMS.

It came to my attention when publishing it shows "no databases found int he project".

Would this effect me not being able to access the database and bringing up the 500 error when logging in and how do i fix this.

No databases found in the project

2
If your using SQL, then you need to have a SQL Server instance setup.Tony Abrams
@TonyAbrams im using SQLExpressuser12063516

2 Answers

0
votes

How did you created your database locally in the first place? Did you manually ran the database update command? I would suggest you add to your startup.cs file a code to ensure your database is created and any missing migrations were applied, you can achieve this within your Configure method:

 using (var scope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
 {
     scope.ServiceProvider.GetRequiredService<DbContext>().Database.Migrate();
 }

Or just EnsureCreated() instead of Migrate() if you don't to apply missing migrations on future loads.

0
votes

It seems that you need to change your ConnectionString configuration in appsettings.json from the format

"Data": {
    "DefaultConnection": {
       "ConnectionString": "xxxxxx"
    }
}

to:

"ConnectionStrings": {
    "DefaultConnection": "xxxxxx"
}

And your startup with

services.AddDbContext<ApplicationDbContext>(opt => opt.UseSqlServer(Configuration["ConnectionStrings:DefaultConnection"]));