Using SQLite on AWS EC2

2019-08-17 05:50发布

问题:

On an Amazon Windows EC2 instance I've created a simple Windows Forms app in VS2017 Express that just logs to C:\Data\Databases\File.txt and opens up a sqlite database C:\Data\Databases\Database.db using Entity framework.

This works absolutely fine on my local machine and other machines when I install it.

Once I've installed it to the EC2 though, it doesn't look like sqlite works properly. The text log is written to, and when doing a FileExists, the database is found.

However as soon as it hits a "using"

public class databaseDB : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlite(@"Filename=C:\Data\Databases\Database.db");
    }
}

try
{
    using (databaseDB db = new databaseDB())
    {
       StaticFunctions.WriteToLog("Selecting...");
    }
}
catch (Exception ex)
{
    StaticFunctions.WriteToLog("Error!");
    StaticFunctions.WriteToLog(ex.InnerException.ToString());
}

the following error log is written:

System.IO.FileNotFoundException: Could not load file or assembly 'System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified. File name: 'System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.ValueTuple, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified. File name: 'System.ValueTuple, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

which I've read generally it means that SQLite isn't installed properly. I've tried registering various sqlite dll's on their own, but keep getting "The module was loaded but the entry-point DllRegisterServer was not found." error.

I've also read that copying the sqlite dll to the application directory sometimes works, but as it's an app, Windows seems to bury the installation somewhere that I can't get to.

What can I do to try and get this working?

Thanks!

回答1:

Turns out it was down to this: Could not load file or assembly 'System.ValueTuple'

AWS EC2 had .Net framework 4.7.2 installed, and I was developing in 4.6.1. Once I installed 4.7.2 on my developer instance, I had the same issue, so updated all the Nuget packages in the project, and now it all works.