EF Migration error
hi,
I am getting an error message, and I am guessing comes from the connection string Initial catalog that I named after the name of the project from lack of info in all the sources I looked into. i followed the documentation and added App.config with a connection string and also read the page for ConfigurationManager but no one seems to tell how to name the "initial catalog" . i am following the dotNet tutorial on EF ,if anybody could help me out i really appreciate, thanks
App.config
on package console
20 Replies
First time ever I see the connection string configured inside of some random XML file
appsettings.json
is usually where that config ishttps://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-strings#winforms--wpf-applications
Connection Strings - EF Core
Managing connection strings under different environments with Entity Framework Core
Ah, a desktop project, that'd explain the XML
do you see any flag?
Well, the error is about the connection string being empty. The only thing that comes to mind is either the XML file not being added to the configuration, or a name mismatch
C# in general is case-sensitive, so
connectionString
property in that XML might be an issue
Not surei didnt add the App.config anywhere (other than it being in the solution) should i add it in App resources or anywhere else?
its not, i try that, the solution build is fine.... no errors
Where is that XML you pasted if not in
App.config
..?my solution didnt have an app.config so i added, its side by side with app.xaml
i meant reference if that was not clear
It should be in the root of your project, IIRC
I'm honestly not sure
it is
I never had the need to connect to a database from a desktop app
how would you store data?
I generally don't make desktop apps, but I'd probably just use SQLite instead of LocalDB
this is kind of breaking the flow.. just needed to store values locally
With SQLite, I wouldn't even use config, I'd just hardcode the connection string as
"database.db"
and call it a daywell that would be an option i guess, just try to learn and they say to not hard code.. but either way am i not using sqll? that name is all over
With EF? No, you won't be writing any SQL code, you'd be using LINQ
well yes but the data is stored in sql i had to get the nuget for sql from ef
SQL is a language
The data would be stored in a database
Whether that database is SQLIte, PostgreSQL, MariaDB, LiteDB, or SQL Server, that's another thing
You probably had to get the nuget for SQL Server
Since that's what LocalDB is based on
ok, i think is sql server actualy
will try to hardcode that string to the overide
it works when hardcoded. weird, before get this "closed" if anybody knows what was wrong in the app.config or ConfigurationManager please let me know, thanks
@Angius thanks for your time
Anybody has an idea on how to fix this issue and not hardcode the connection string? thanks