Click here to Skip to main content
15,356,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, I want to send data to an online database by using the c# desktop base application.
please suggest to me what is the best approach.
I have my online MySQL database hosted on a Hostinger server.

What I have tried:

I did not try anything, at the moment I'm saving my data to my Local SQL server
Updated 6-May-22 18:15pm

1 solution

Two things you need to know:

1) The code to access a MySql server is not the same as that to access an SQL Server instance. You would need to start by replacing SqlConnection with MySqlConnection, SqlCOmmand with MySqlCommand, and so forth - which means your code is untested when it accesses the production server - this is what's known as a "very bad idea"!
Then you will probably need to make changes to the actual SQL commands you send to the DB as the SQL Server and MySQL syntax is not identical: SQL Syntax differences between MSSQL and MySQL[^] may help, but again, this means your software will be untested when it reaches the production server.

You should install a local MySql Server to test your code against rather than SQL Server or you risk destroying the production DB.

2) Remote access. It may not work at all, and if it does it's probably a major security risk. Most hosting services do not open databases up directly to the "outside world" to prevent such security problems: they expect you to either use something like WCF to provide a security middle man, or write web-based code to access the DB from within their firewalls. Security then becomes your problem, not theirs! Contact Hostinger tech support (I've never heard of them, so I can't tell you if they do allow remote access or not) and ask them. If you can directly access the DB via the internet, then I'd be pretty worried about what I put in there, given GDPR among other things.

If you need remote access to a DB, you are probably better off going with a cloud based solution rather than direct querying.
Fahid Zahoor 7-May-22 5:07am
thanks for suggestion but i'm thinking to sync the data from local SQL Server to online mysql db , i want to make a backend service that sync all the new records from local SQL Server to online mysql database using c#.
so please can you tell me which approach you prefer most.
1-Direct Query
2-Using Api

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900