简体   繁体   English

ASP.NET Core 2.0 Web 应用程序在将项目部署到 Azure Web 服务时失败并出现 SQLite 错误,但在本地环境中运行良好

[英]ASP.NET Core 2.0 Web Application fails with a SQLite error when deploying the project to Azure Web Service but runs fine in local environment

The ASP.NET Core 2.0 web application fails when I deploy it to Azure App Service.当我将 ASP.NET Core 2.0 Web 应用程序部署到 Azure 应用服务时,它会失败。

This is what is being used in the project.这就是项目中正在使用的内容。

  • ASP.NET Core 2.0 MVC Web Application ASP.NET Core 2.0 MVC Web 应用程序
  • Visual Studio 2017 Enterprise Visual Studio 2017 企业版
  • SQLite databases SQLite 数据库
  • Code First Entity Framework代码优先实体框架
  • Azure App Service Azure 应用服务

The web application works fine when I run it locally in Visual Studio.当我在 Visual Studio 中本地运行 Web 应用程序时,它运行良好。 The problem results when I publish it to an Azure Web Service it cannot connect to the database.当我将其发布到 Azure Web 服务时,问题导致它无法连接到数据库。 It states the following error when navigating to the deployed web application URL:导航到已部署的 Web 应用程序 URL 时,它指出以下错误:

SqliteException: SQLite Error 1: 'no such table: Inventory'. SqliteException:SQLite 错误 1:“没有这样的表:库存”。

I've tried several times to apply an Update-Migration or an Add-Migration to the database but it will still result in the table not found when deployed to the Azure server.我曾多次尝试将Update-MigrationAdd-Migration应用于数据库,但在部署到 Azure 服务器时仍会导致找不到表。

Here are my SQLite connections defined in the Startup.cs file.这是我在 Startup.cs 文件中定义的 SQLite 连接。

     // Add Inventory DB
        services.AddDbContext<InventoryContext>(options =>
        options.UseSqlite("Data Source=Inventory.db"));

        // Add User DB
        services.AddDbContext<UserContext>(options =>
        options.UseSqlite("Data Source=User.db"));

        // Add Purchase Order DB
        services.AddDbContext<PurchaseOrderContext>(options =>
        options.UseSqlite("Data Source=PurchaseOrder.db"));

Following @Derek solution, i modified my connection string on appsettings.json as i am using Configuration.GetConnectionString to fetch the connection string, and moved sqlite db to App_Data folder to wwwroot..按照@Derek 解决方案,我修改了appsettings.json上的连接字符串,因为我正在使用Configuration.GetConnectionString来获取连接字符串,并将 sqlite db 移动到 App_Data 文件夹到 wwwroot..

"ConnectionStrings": {
    "MyAppContext": "Data Source=./wwwroot/App_Data/myapp.db"
}

将 SQLite 数据库放在 .NET 解决方案目录中的“AppData”文件夹中,并将您的连接字符串指向该新位置。

暂无
暂无

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

相关问题 部署多项目 ASP.NET 核心 web 应用程序到 Azure 应用程序服务使用 ZE1ADBCBB92C622D0B3E Actions61 - Deploying multi-project ASP.NET Core web app to Azure App Service using Github Actions 将ASP.NET Core部署到Azure Web App服务错误 - Deploy ASP.NET Core to Azure Web App Service Error ASP.NET Core 1.1 在本地运行良好,但在发布到 Azure 时显示“启动应用程序时出错”。 - ASP.NET Core 1.1 runs fine locally but when publishing to Azure says “An error occurred while starting the application.” 使用 Web Deploy 在 Azure 中部署普通的 ASP.NET Core 2.2 Web 应用程序引发错误 - Deploying a plain ASP.NET Core 2.2 Web App in Azure using Web Deploy is throwing an error ASP.NET 4.5在ASP.NET Core 2.0应用程序下的Azure Web App中作为虚拟应用程序抛出502.5 - ASP.NET 4.5 throws 502.5 as a virtual application in Azure Web App under a ASP.NET Core 2.0 application 访问仅在本地计算机上运行的ASP.NET Web应用程序 - Accessing ASP.NET web application that only runs on a local machine 当我将 ASP.NET Core web 应用程序部署到 Azure 时,为什么没有检测到我的环境设置? - Why are my environment settings not being detected when I deploy my ASP.NET Core web application to Azure? ASP.Net Core 2.0 Web应用程序中的本地化 - Localization in ASP.Net Core 2.0 Web Application 在asp.net core 2.0 Web应用程序中使用NLog - Using NLog in asp.net core 2.0 web application 当托管在Azure应用程序服务中时,如何控制添加到ASP.NET核心Web应用程序中的HTTP响应标头? - How can I control the HTTP response headers added to my ASP.NET core web application when hosted in Azure app service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM