Question

i have a PHP website and MySQL database in same web sever. i wont to connect that MySQL database with c# application. my c# application in run another computer. how can i connect that MySQL database ?

No correct solution

OTHER TIPS

First make sure you have downloaded and installed the MySQL Connector/NET from the MySQL official website. In this article, I will use the Connector/NET version 6.1.

Then add MySql.Data namespace in Reference

Then you can use mysql in .net

now create a connection strin like this

     class ConnectToMySql{
           private MySqlConnection connection;

         private void Initialize()
         {
         server = "localhost";
         database = "connectcsharptomysql";
         uid = "username";
         password = "password";
         string connectionString;
         connectionString = "SERVER=" + server + ";" + "DATABASE=" + 
         database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";

         connection = new MySqlConnection(connectionString);
         connection.Open();
      }


}

Then

1 Create a MySQL command. 2 Assign a connection and a query to the command. This can be done using the constructor 3 using the Connection and the CommandText methods in the MySqlCommand class. 4 Create a MySqlDataReader object to read the selected records/data. 5 Execute the command. 6 Read the records and display them or store them in a list. 7 Close the data reader. 8 Close the connection.

I tooth this will help full for you . now you can start working on mysql in .NET

Best of luck

you firstly have to add mysql ref to your project: plz right click on your project and go to the ref part in it after that try to find mysl.conncetor and tick it and refresh your project and firstly try to add using mysql.net.client now you can use data base located in the mysql db from c# coding be sure you have downloaded both mysql connector and installaton which is about 500 mb files.

class ConnectToMySql{
   private MySqlConnection mscon;
   private void Initialize()
   {
     server = "localhost";
     database = "your own database name";
     uid = " your username";
     password = "your password";
     string const;
     connectionString = "SERVER=" + server + ";" + "DATABASE=" + 
     database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";

     mscon= new MySqlConnection(const);
     mscon.Open();
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top