Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

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/

share|improve this answer
    
tnx,but my question is about connect windows app to website –  abbas mahmudi Jun 6 '13 at 13:41
    
for examole user open app and upload his file,then app connect to my website and sace his file to it –  abbas mahmudi Jun 6 '13 at 13:42
    
@abbasmahmudi - I've updated my answer. –  Giedrius Jun 6 '13 at 13:48
    
+1 for pointing out the security issue –  Drahcir Jun 6 '13 at 13:52
    
tnx again,how i start web service and connect this to my app –  abbas mahmudi Jun 6 '13 at 15:15

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

share|improve this answer

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.

share|improve this answer
    
tnx,but i wanna connect too mysql in website not in my computer –  abbas mahmudi Jun 6 '13 at 10:09
    
I didn't test it but I think if you put your IP as ServerName it works –  Beatles1692 Jun 6 '13 at 10:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.