簡體   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

當我將 ASP.NET Core 2.0 Web 應用程序部署到 Azure 應用服務時,它會失敗。

這就是項目中正在使用的內容。

  • ASP.NET Core 2.0 MVC Web 應用程序
  • Visual Studio 2017 企業版
  • SQLite 數據庫
  • 代碼優先實體框架
  • Azure 應用服務

當我在 Visual Studio 中本地運行 Web 應用程序時,它運行良好。 當我將其發布到 Azure Web 服務時,問題導致它無法連接到數據庫。 導航到已部署的 Web 應用程序 URL 時,它指出以下錯誤:

SqliteException:SQLite 錯誤 1:“沒有這樣的表:庫存”。

我曾多次嘗試將Update-MigrationAdd-Migration應用於數據庫,但在部署到 Azure 服務器時仍會導致找不到表。

這是我在 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"));

按照@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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM