简体   繁体   中英

How to properly connect C# and MySQL

I have an application that I created in C# WinForms. I also have a MySQL database, which is not publicly accessible (only from related webhosting) - so no MySQL Connector available.

What I did is, that I send data from C# via POST method to PHP and PHP code execute my SQL queries. In case of SELECT query - PHP returns result in JSON string, which I deserialize in C# through some JSON DESERIALIZING extension.

I want to do the same app in C# WPF and later on with ASP.NET and maybe some PHP/JS(REACT) to train my knowledge with these platforms/languages/frameworks...

Which means - I would like to ask you, what do you think is the best way, to create the communication either for C# WinForm/WPF to MySQL and ASP.NET to MySQL?

I did some small research and found some technologies like: RESTful and SOAP. There are many others I believe, but I don't know which one I should really focus on. Which is the best for now and future? It doesn't matter how hard is to learn the technology! So "this is the simplest solution for your small app" is not the proper solution i am looking for as I am going to do larger apps in future and I want to focus on the best available technology,

Ask for more if needed.

Thanks.

There is only ONE way to do that - which is using ADO.NET DbConnection subclasses that are provided by the MySQL package.

Which you can find at.... https://dev.mysql.com/downloads/connector/net/

for the oddicial one. There are alternatives, paid and free.

Now, some will say "what about dapper" or "what about entity framework".

WRONG QUESTION. See, both of those, and all other ORMs - use the ADO.NET DbConnection subclasses internally to CONNECT. THey pack them up in nicer (better) API's, but that is explicitly NOT the question here.

Now:

I did some small research and found some technologies like: RESTful and SOAP

BAD research. Both REST and SOAP are NOT TOOLS FOR THE QUESTIOn. They are tools on how to expose an ASP.NET API so other things can connect to it - they do not talk about where the data comes from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM