How to integrate a Mysql database with a C#application?

Asked

Viewed 941 times

1

I’m a beginner in database and I have a simple C# application and I want to use the Mysql database to store the data.

I have Mysql Server installed and usually use the "command-line client" where I already have a test table created "Account" containing the columns: id, user, and password. db = "test".

*I have already assigned the "Mysql.Data.Mysqlclient" reference to the class where I will be performing operations with the databank.

Questions:

  1. How can I set up the Connection string correctly?
  2. After the string has been configured and the connection has been established, how can I integrate the database to the final C# project to be able to distribute it normally "executable" or even move the locality project without having problems with the Mysql address of the developer machine?
  3. Following question 2, there is a way to keep the database within the C#project, where, I can modify it gradually in different locations without having any problem regarding the change of address in the string?
  4. As for modifying and updating the tables in a future update in the project created, how can I modify it in my sql server (update the file keeping the connection string)?
  • Dude, put in here what you tried and the mistake you found. If you haven’t tried, a simple read in the documentation or a practical example you find in the first Google result for "mysql c#" answers most of your questions.

1 answer

2

How can I set up the Connection string correctly?

You can use a file udl for that reason. Mysql client needs to be properly installed on your machine.

After the string has been configured and the connection has been established, how can I integrate the database to the final C# project to be able to distribute it normally "executable" or even move the locality project without having problems with the Mysql address of the developer machine?

The best way is to manage your project using packages. In the case of C#, the solution is called Nuget. Mysql package in Nuget is accessible here.

Your concern will be just copy the files to the target machine without worrying about installations and things like.

Following question 2, there is a way to keep the database within the C#project, where, I can modify it gradually in different locations without having any problem regarding the change of address in the string?

Yes, but this will make you abandon Mysql and use a database whose format is local. There are two great database technologies for this:

As for modifying and updating the tables in a future update in the project created, how can I modify it in my sql server (update the file keeping the connection string)?

You can use a data abstraction framework that does this control incrementally, such as the Entityframework.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.