简体   繁体   English

将带有实体框架的 Publish.Net Core 应用程序发布到 IIS

[英]Publish .Net Core app with Entity Framework to IIS

I am trying to published my.Net Core app to IIS that uses Entity Framework.我正在尝试将 my.Net Core 应用程序发布到使用实体框架的 IIS。 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我遵循了不同的教程,包括: 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.我对发布和托管 web 应用程序比较陌生,所以我不确定该怎么做。

At the moment my frontend of the web app loads on IIS but when I go to login it brings up a 500 error.目前我的 web 应用程序的前端加载到 IIS 但是当我 go 登录时会出现 500 错误。 I have included my connection string and added a user and gve correct permissions under SSMS.我已经包含了我的连接字符串并添加了一个用户并在 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.这是否会影响我无法访问数据库并在登录时出现 500 错误以及如何解决此问题。

No databases found in the project在项目中找不到数据库

How did you created your database locally in the first place?您最初是如何在本地创建数据库的? Did you manually ran the database update command?您是否手动运行了database update命令? 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:我建议您在您的startup.cs文件中添加一个代码,以确保您的数据库已创建并应用了任何缺少的迁移,您可以在您的Configure方法中实现这一点:

 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.或者,如果您不对未来的负载应用丢失的迁移,则只需EnsureCreated()而不是Migrate()

It seems that you need to change your ConnectionString configuration in appsettings.json from the format看来您需要从格式更改 appsettings.json 中的 ConnectionString 配置

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

to:至:

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

And your startup with你的创业公司

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 ASP.NET Core 应用程序发布到 Azure 不起作用 - Publish ASP.NET Core app to Azure not working 如何在.NET Core 1.0中使用Entity Framework运行sql脚本? - How to run sql script with Entity Framework in .NET Core 1.0? 如何在ASP.NET Core项目中设置实体框架 - How to setup Entity Framework in ASP.NET Core project .NET核心-实体框架-急于加载Include()的意外行为 - .NET Core - Entity Framework - Unexpected Behaviour with Eager Loading Include() 使用iis的主机.net核心应用程序会出现数据库访问错误 - Host .net core app with iis give a database access error WCF和IIS的实体框架问题 - Entity framework issue with WCF and IIS IIS网站(.net / mvc /实体框架)发布到活动服务器时抛出“找不到网络路径错误” - IIS Website (.net / mvc / entity framework) published to live server is throwing 'network path not found error' 将 ASP .NET 应用程序发布到 IIS 时出现 SQL 和 IIS 错误 - SQL and IIS error when publish an ASP .NET application to IIS 实体框架核心查询生成 - Entity Framework Core Query Generation 在 Entity Framework Core 上禁用 AutoDetectChanges - Disable AutoDetectChanges on Entity Framework Core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM