Connect to web MySQL from c# desktop program?
I've got a webserver running quite standard Apache/php/MySQL and want to connect to this MySQL database from a desktop 开发者_如何学Capplication written in c#/wpf.
First, how can I connect? Do I need some special SQLConnection library?
Second, how safe is this? Anything special I need think about for security since the database is in the web and not local?
Anything special I need think about for security since the database is in the web and not local?
Well, I would say, that one should not expose the database directly to the web, under almost any circumstances. Mostly for security reasons, too.
Maybe you should write a web API (REST/RPC/whatever) to your data and access it over HTTP instead? This way you don't need to expose the actual database to the whole internet AND you have a chance of being database-schema-agnostic (you desktop app doesn't need to care about the structure of your database, but only about the interface your web service provides).
You could connect to MySQL if you allow connections (to MySQL) from the IP addresses the desktop (WPF) clients are running from. Just create users and allow them to connect directly to the database. It's not unsafe. But your MySQL repository could become harder to maintain (you will have lots of users, logging from different subnets, etc.).
I would recommend to create a WEBSERVICE or RESTFUL API in your Apache/PHP/MySQL Server, and connect to that service with C#.
精彩评论