3

I am running into an issue where the code is unable to find my existing Sqlite database that is in the same folder as this code that is calling it. The error I am getting is, "SQLite Error 1 table does not exist." I know the table exists, it is just unable to find the path. What am I doing wrong?

Note: I am not creating a code first Sqlite database. This is opening an existing Sqlite database

DATABASE CONTEXT CODE

using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyWidget.Domain.Data
{
    public static class MyWidgetService
    {
        public static void GetAll()
        {            

            using var context = new MyWidgetContext();
            if (context.Translations.Any())
            {
                var data = context.Widgets.ToList(); 
                foreach (var widget in data)
                {
                    Console.WriteLine(widget.ProductName);
                }
            }
            else
            {
                Console.WriteLine("No widgets found");
            }
        }
    }
}

**DATABASE SERVICE CODE

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
using Microsoft.EntityFrameworkCore;

namespace MyWidget.Domain.Data
{
    public class MyWidgetContext : DbContext
    {
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlite(connectionString: "Filename=./MyWidgetDB.db");
        }

        public DbSet<WidgetData> Widgets { get; set; }
    }

    public class WidgetData
    {
        public int Id { get; set; }
        public string ProductName { get; set; }

    }
}

2 Answers 2

2

I had the same problem: SqliteException: SQLite Error 1: 'no such table: ScanFolders'. I used the SQLlite Browser to inspect the database in the debug folder and it had no tables. Checking the properties on the db was set to "Do Not Copy" I changed it to "Copy if Newer" and that fixed the issue for me.

Sign up to request clarification or add additional context in comments.

1 Comment

This comment helped. also I applied it to *.db-shm, and *.db-wal file which showed up in the Solution Explorer under the *.db file.
1

I decided to go another direction and use Dapper and System.Data.Sqlite.Core. This video by Tim Corey perfectly explains how to implement it:

https://www.youtube.com/watch?v=ayp3tHEkRc0

This methodology works really well and am using it in my GitHub project:

https://github.com/encouragingapps/Blender3DReference

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.