0

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?

3 Answers 3

2

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/

Sign up to request clarification or add additional context in comments.

3 Comments

tnx,but my question is about connect windows app to website
for examole user open app and upload his file,then app connect to my website and sace his file to it
tnx again,how i start web service and connect this to my app
0

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

Comments

0

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.

2 Comments

tnx,but i wanna connect too mysql in website not in my computer
I didn't test it but I think if you put your IP as ServerName it works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.