[英]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.这就是项目中正在使用的内容。
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-Migration或Add-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.