C
C#3mo ago
hutoanhill

What's up with SQLite and Jetbrains Rider

I am debugging a metod and its saying a row is missing from the table. This made no since, so i wiped open SQLiteStudio and took a loo at the file. the row is there alright. So i add a breakpoint and check the connection.
private const string ServerDataConnection = "Data Source=ServerData.db;Version=3;";
using (var connection = new SQLiteConnection(ServerDataConnection)) {
private const string ServerDataConnection = "Data Source=ServerData.db;Version=3;";
using (var connection = new SQLiteConnection(ServerDataConnection)) {
The connection has a property, FileName, that i assume has the FilePath of the sqlite file. its pointing to a file in /bin/debug file, not my sqlite file. what's up with this??? why not point at the file in my primary directory?
No description
108 Replies
Jimmacle
Jimmacle3mo ago
because that's not the typical working directory for C# programs the default working directory is the location of the built executable if you have data that you want copied to the output folder, you can configure that per file in the IDE by right clicking the file and going to properties or use an absolute path instead of a relative one, then it doesn't matter what the working directory is
hutoanhill
hutoanhillOP3mo ago
would that be a build action?
Jimmacle
Jimmacle3mo ago
no, it's the "copy to output directory" option below that
hutoanhill
hutoanhillOP3mo ago
oh, i see that
Jimmacle
Jimmacle3mo ago
build action should be none for regular non-code files
hutoanhill
hutoanhillOP3mo ago
is there a way i can make changes come back when we are done building?
Jimmacle
Jimmacle3mo ago
what do you mean if you want to work on the file your program is also working on, just put it in the bin folder and don't have anything in your source folder
hutoanhill
hutoanhillOP3mo ago
so my program makes changes to this database. idealy is back here where i can look at it once the program makes changes
Jimmacle
Jimmacle3mo ago
or use the absolute path option
hutoanhill
hutoanhillOP3mo ago
k, i will have to put that in a config so i dont screw this up when i finish this and deploy it thx so thats what a bin folder is... amazing ive gotten this far not knowing that.
Jimmacle
Jimmacle3mo ago
yeah that's where your actual program ends up
hutoanhill
hutoanhillOP3mo ago
very very good to know
Jimmacle
Jimmacle3mo ago
if you wanted, you could copy those files to some other place/computer and run the exe and it would run (assuming the .NET runtime is installed)
hutoanhill
hutoanhillOP3mo ago
no clue! my c# class didnt do much more than mention .NET existed. frankly not sure what the diferance is between c# and .NET
Jimmacle
Jimmacle3mo ago
it's basically all the libraries and other guts that make your C# program actually run
hutoanhill
hutoanhillOP3mo ago
mostly they pushed me off to c++ and i was like nope. oh. i would just call that c#... weird
Jimmacle
Jimmacle3mo ago
well, it's different because C# isn't the only language that runs on .NET there's VB.NET, F#, and some others afaik they all use the same underlying libraries and runtime
hutoanhill
hutoanhillOP3mo ago
nifty. well, i am still getting that weird error about the row not being there for some reason. aaand now SQLiteStudio cant resolve the db boy i am screwed.
Jimmacle
Jimmacle3mo ago
are you trying to open the right file?
hutoanhill
hutoanhillOP3mo ago
yea welp. guess this is a problem for another day. gtg now.
Anton
Anton3mo ago
if you want to automate the sharing of that file, it's all custom there's no checkbox to help you
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
The Fog from Human Resources
Why not use DB Browser :SCfeet: I haven't read the convo here yet just small parts of it But your issue sounds more like a rider issue, what you did there I do all the time in Visual Studio, and there it works properly The behavior you're explaining I experienced with ASP.NET before for some reason and no one was able to explain why this happens
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
I am not doing that. I just have it in bin
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
there's a lot of stuff ive got hardcoded rn, that wont be eventually. filepath to the database is one of those things i didnt ever set up copy to output directory. i leaned what /bin was and just put the db file in there perminantly. i see the issue your talking about. that could actually be really useful for testing, allowing me to quickly reset the state of the db for testing, but it woudl mean i couldent save anyting between states unless i update the file manualy.
The Fog from Human Resources
use EF Core!!!
hutoanhill
hutoanhillOP3mo ago
use what? oh, entity framework no idea what that is people keep talking about it as if everyone knows what it is anyone see any issues with this connection string?
private const string DatabasePath = "C:/Users/<username>/Desktop/GhostOfJoe/hostOfJoe/GhostOfJoe/bin/ServerData.db";

private const string ServerDataConnection = $"Data Source={DatabasePath};Version=3;";
private const string DatabasePath = "C:/Users/<username>/Desktop/GhostOfJoe/hostOfJoe/GhostOfJoe/bin/ServerData.db";

private const string ServerDataConnection = $"Data Source={DatabasePath};Version=3;";
i am now getting an unable to open database error
Jimmacle
Jimmacle3mo ago
the path separators are wrong for windows, idk if sqlite cares they should be \ not /
hutoanhill
hutoanhillOP3mo ago
swapped them no change :( private const string DatabasePath = "C:\\Users\\<username>\\Desktop\\GhostOfJoe\\hostOfJoe\\GhostOfJoe\\bin\\ServerData.db";
The Fog from Human Resources
to me its the most powerful way of interacting with a database works on any SQL database too :soPortuguese:
hutoanhill
hutoanhillOP3mo ago
sounds great
The Fog from Human Resources
yes!!! its simple to setup too no more writing of SQL queries no more query to object parsing only productivity!!!!!
Jimmacle
Jimmacle3mo ago
(not a replacement for knowing SQL)
hutoanhill
hutoanhillOP3mo ago
well i actualy realy like sql, so thats not all bad
Jimmacle
Jimmacle3mo ago
the main advantages of EF Core are the object mapping and type safe queries, and less "not having to write SQL" because you absolutely still need to know the actual SQL that EF Core will produce to avoid writing bad queries
hutoanhill
hutoanhillOP3mo ago
can someone point me to a good walkthough for ef?
Jimmacle
Jimmacle3mo ago
there's a getting started section in this documentation https://learn.microsoft.com/en-us/ef/core/
Overview of Entity Framework Core - EF Core
General introductory overview of Entity Framework Core
hutoanhill
hutoanhillOP3mo ago
that is a good place to start at the very least working on setting up EF. trying to scafold my database (i am using rider so no commandlit) dotnet ef dbcontext scaffold "Data Source=C:\Users\<username>\Desktop\GhostOfJoe\hostOfJoe\GhostOfJoe\bin\ServerData.db;" Microsoft.EntityFrameworkCore.Sqlite --context-dir Data --output-dir Models this crashes with this error SQLite Error 14: 'unable to open database file'. so something is wrong with my connection string and or file Anyone know whats up with my connection string?
hutoanhill
hutoanhillOP3mo ago
found this (https://stackoverflow.com/questions/10875612/unable-to-open-the-database-file) and it seems to sugest i need a version=3; statment, but when i include that i get an error:
Stack Overflow
Unable to open the database file
private void SetConnection() { string a = string.Format(@"Data Source={0};Version=3;New=False;Compress=True;", "~/lodeDb.db"); sql_con = new SQLiteConnection(a); } pr...
hutoanhill
hutoanhillOP3mo ago
Connection string keyword 'version' is not supported.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
no, 6 tables, no data as of yet. just had to rebuild it
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
i am practicing for a larger database with something like 60 tables
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
did the code.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
i figured if i could get it working with the small database, where i can debug easer and know quickly if its right and i can scale it. on top of that, the issue with not being able to access the SQLite database is not just with this command. I get the same error trying to access the data from my code
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
yea thats why i am trying to get it to work. but if i cant even connect to the database i am not going to get very far.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
why?
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
that would be a problem yes
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
ok. so where do i put my config.json file?
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
ive seen appsettings.json and i know there is some fancy way of accessing it. I dont know it. I just implemented my own quick method to grab data from a config.json file
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
fancy way of accessing it within the code, not the editor
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
give me a few min. i gotta throw some kinda sensitive stuff in a config before i make that repo public
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
weee. welp its not a big issue. i can always regenerate it. no it just the private key for my discord bot which i can just rebuild in like 2 min
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
its so losely attached to my code and still in development so its just on my private server
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
yep.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
glad i am making these mistakes on the prodotype
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
ok. i gotta start from the begining. gotta figure out secrets like i said, fancy stuff no one ever explanes for some reason
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
yea thats a good idea. the bot doesent even run in the current state anyways.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
this is not how to get an enverimental vars... i dont know how of if there is an extra step, but this is not it.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
what.... hm. ah. bet i got it ok. got that ok. thats the only truely sensitive bit of info in the system. everthing else is server/channel/user ids which i am falry sure are all publicly accessable anyways.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
nope. all discord ids. the only identifying info ive got is the id of peoples discord users, (publicly accessable) and the if servers they are in (also publicly accessable) but also, the db is empty rn... so... none of that data. The end state of the projct will be that the database will per persistant on a server somewhere and i will modify the cs project and push the build to the server and restart it. but i havent gotten there yet. worst think that could happen is people might be able to DM a frend of mine while not being in the same server as him which is not really an issue as there would be easer ways to find him.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
ok... making repo public...
hutoanhill
hutoanhillOP3mo ago
GitHub
GitHub - hutonahill/GhostOfJoe
Contribute to hutonahill/GhostOfJoe development by creating an account on GitHub.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
good to know. will fixt that right off the bat
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
nope, its in the bin which you cant cuz its .gitignore
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
same. here let me zip that real quick
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
great. downgraded the packages to .NET 8
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
yep. most of them are still on 8.0.0, but a few are newer.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
i just went into NuGet, uncheck pre release, then downgraded all the packages
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
hm.... whats the reason to use appsettings.json over my config system? because, like the op for this stack post, i need to modify my settings programmatically. I've already got my bot set up so i can modify the settings from it... so i think i am just not going to use the appsettings.json system...
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
what does this mean?
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
hm. well ive kinda already done that with my config system...
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
ok. fine *grumpy noises * i will figure DI
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hutoanhill
hutoanhillOP3mo ago
ok. lets start with my requirements 1) i need a place to store a handful of my bots settings i don't want to store in SQLite. current solution is a config.json file. I need to be able to access my config object within my program and i need to be able to programaticly make changes to it. 2) i need a safe place to store secrets like my API key. can Host.CreateDefaultBuilder do this? also, this is not a window form application. Its command line so i assume a line like this: services.AddSingleton<Form1>(); needs to be somthing else (ive got to sleep. be back in a few hours)
Want results from more Discord servers?
Add your server