Database Connection
Hello. I am very new to C# and I barely know anything. I was wondering if somebody could show me how to connect and use a SQL database for a login form in a C# .NET WinForm.
10 Replies
Is it for a program you intend to release?
You have two choices - "direct" connection via something called ADO, or using a library to help manage the data, called an ORM. There are several ORMs in C#, but the most commonly used one is EntityFramework Core
However, the question asked above is important. Is this just for learning, or is it actually for a program you plan to release to the public?
Because doing manual SQL queries to a local database is fine for learning, but if you plan to release this, it means the users must have their own SQL databases, or worse, you have to expose a database to the internet with valid credentials "hidden" inside the program. Thats a major security flaw.
I am looking for the database to work on different computers. But, security is not an issue because this won't be used as a real program or service. I am making this for learning purposes. I want to learn how to connect a database and use it with a login form and then give other people the build and it will still work.
Also, thank you so much for both you responding so fast and willing to help. Sorry for the very delayed response.
So you want the database to be local to the app, or a shared database for all users?
if its local to the app, just use SQLite and you're golden.
if you want a shared database, you'll need to set up a webapi that acts as a gateway to the database, and find hosting for it
I am not sure. But, if I give the program to my friend the login should work as it did on my device.
That means a shared database.
This is significantly more work and involves hosting, as your program needs a way to "call home" to the database
what can I use to host my database?
A $vps
Cheap recommendations
https://www.scaleway.com https://www.digitalocean.com
https://www.linode.com https://www.ovh.co.uk
https://www.time4vps.eu https://www.vultr.com
https://www.hetzner.com https://contabo.com
Always free options
https://cloud.google.com/free
https://www.oracle.com/cloud/free/#always-free
You will also need hosting for the api, which can be done with the same vps