abbas mahmudi
abbas mahmudi

Reputation: 175

connect mysql database in webserver with c# program in windows

I have a website. My database is MySQL and now I want to write a program with C# that the user can use this app to upload their file to my website

How can I connect a C# program in Windows with a MySQL database on a web server?

Upvotes: 0

Views: 1464

Answers (3)

Giedrius
Giedrius

Reputation: 8550

You can use Entity Framework with MySql connector. Here's tutorial how to use it: http://dev.mysql.com/doc/refman/5.1/en/connector-net-tutorials-entity-framework-winform-data-source.html

As alternative you can use NHibernate: http://www.codeproject.com/Articles/26123/NHibernate-and-MySQL-A-simple-example

Also, as SamiHuutoniemi mentioned, you can use MySql connector without ORM, by simply using data reader: http://dev.mysql.com/doc/refman/5.0/es/connector-net-examples-mysqldatareader.html

Update: Ups, looks like I misunderstood the question. Short answer is - you don't wish to communicate directly with your website's database from desktop, as it involves many issues, one of them is security - you will need to open your database access from outside. I would suggest to make a page (web service) on your existing website that would accept requests from c# client and transform those requests into actions with database.
Not sure what technology your current site is using, but if that is PHP, this page lists few of them: http://blog.programmableweb.com/2011/09/23/short-list-of-restful-api-frameworks-for-php/

Upvotes: 2

Beatles1692
Beatles1692

Reputation: 5330

You can use an OleDbConnection to connect to mysql: For example:

using System.Data.OleDb;

    public class DataAccess
    {

          public void Connect(Action<OleDbConnection> action)
          {
                    using(var cnn=new OleDbConnection())
                   {
                       cnn.ConnectionString="Provider=MySqlProv;Data Source=ServerName;User id=UserName;Password=Password;" 
                       cnn.Open();
                       action(cnn);
                   }
           }
    }

Here you can find more useful information.

Upvotes: 0

SamiHuutoniemi
SamiHuutoniemi

Reputation: 1595

If you do not use Entity Framework, you can also download Oracle's .NET connector.

Upvotes: 0

Related Questions