My project builds with no errors. The home page loads when I click on the Run arrow.
But when I click the link to display the Courses View I get this error below "SQLite Error 1: 'no such table: Courses'."
Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1: 'no such table: Courses'.
at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
at Microsoft.Data.Sqlite.SqliteCommand.PrepareAndEnumerateStatements(Stopwatch timer)+MoveNext()
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteAsync(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.BufferlessMoveNext(DbContext _, Boolean buffer, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.MoveNext(CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext(CancellationToken cancellationToken)
at System.Linq.AsyncEnumerable.Aggregate_[TSource,TAccumulate,TResult](IAsyncEnumerable`1 source, TAccumulate seed, Func`3 accumulator, Func`2 resultSelector, CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Aggregate.cs:line 120
at OESAC.Pages.Courses.IndexModel.OnGetAsync() in J:\OESAC\Pages\Courses\Index.cshtml.cs:line 30
Here is my code iin the .cs file. It runs right up to the OnGetAsyc
namespace OESAC.Pages.Courses
{
public class IndexModel : PageModel
{
public readonly OESAC.Data.MyDbContext _context;
public IndexModel(OESAC.Data.MyDbContext context)
{
_context = context;
}
public IList<CoursesViewModel> CoursesVM { get;set; }
public async Task OnGetAsync()
{
//CoursesVM = await _context.Courses.ToListAsync();
CoursesVM = await _context.Courses
.Select(p => new CoursesViewModel
{
OESACID = p.OESACID,
CourseTitle = p.CourseTitle,
Instructor = p.Instructor,
Locations = p.Locations,
Dates = p.Dates,
CEUDWP = p.CEUDWP,
CEUDEQ = p.CEUDEQ,
CEUonsiteInstall = p.CEUonsiteInstall,
CEUonsiteOandM = p.CEUonsiteOandM,
MaxCEU = p.MaxCEU,
SponsorID = p.SponsorID,
MrMs = p.MrMs,
CurrentContactName = p.CurrentContactName,
ContactBizName = p.ContactBizName,
ContactAddress = p.ContactAddress,
ContactCity = p.ContactCity,
ContactState = p.ContactState,
ContactZip = p.ContactZip,
CurrentContactPhone = p.CurrentContactPhone,
CurrentContactFax = p.CurrentContactFax,
CurrentContactEmail = p.CurrentContactEmail,
DateRec = p.DateRec,
FeeRec = p.FeeRec,
CheckNumber = p.CheckNumber,
PrelimAprvDate = p.PrelimAprvDate,
MailedReceipt = p.MailedReceipt,
FinalAprvDate = p.FinalAprvDate,
MailedFinal = p.MailedFinal,
HomeStudy = p.HomeStudy,
Recurring = p.Recurring,
PutOnCommitteeList = p.PutOnCommitteeList,
FinalLetterSent = p.FinalLetterSent,
URL = p.URL,
ThreeYearLetterSent = p.ThreeYearLetterSent,
TakeOffWeb = p.TakeOffWeb,
Inactive = p.Inactive
}).ToListAsync();
}
}
}
Here is my Startup.cs file
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
//services.AddDbContext<MyDbContext>(options => options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
services.AddEntityFrameworkSqlite()
.AddDbContext<MyDbContext>(
options => { options.UseSqlite($"Data Source=./Data/sqlite/oesac_new.db"); });
Here is my appsettings.json file
{
"ConnectionStrings": {
"DefaultConnection": "Dsn=SQLite3 Datasource"
},
I have tried all sorts of connection strings from absolute path to database, relative path, etc.
I can see the Sqlite database in my Server Explorer where I "made new connection".
I can see the tables and their data.
it gives me the connectionString besides the datasource name in the properties.
Either one is successful if I click "Test Connection" button.
Dsn=SQLite3 Datasource;database=J:\OESAC\Data\sqlite\oesac_new.db;stepapi=0;syncpragma=NORMAL;notxn=0;timeout=100000;shortnames=0;longnames=0;nocreat=0;nowchar=0;fksupport=0;oemcp=0;bigint=0;jdconv=0
My assumptions are that the connectionString is correct, but it says no table named "Courses" exists!
I am pulling my hair out here.