I'm trying to connect from my C# windows application to MySQL database which is on my host of my website.How can i make connection? I downloaded a simple connection project from "Codeproject" but it's not inserting anything.I also installed MySQL connector 6.1 as required.
server = "" //local host in php
database = "database";
uid = "username";
password = "pass";
string connectionString;
connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
connection = new MySqlConnection(connectionString);
}
//open connection to database
private bool OpenConnection()
{
try
{
connection.Open();
return true;
}
catch (MySqlException ex)
{
//When handling errors, you can your application's response based on the error number.
//The two most common error numbers when connecting are as follows:
//0: Cannot connect to server.
//1045: Invalid user name and/or password.
switch (ex.Number)
{
case 0:
MessageBox.Show("Cannot connect to server. Contact administrator");
break;
case 1045:
MessageBox.Show("Invalid username/password, please try again");
break;
}
return false;
}
}
//Close connection
private bool CloseConnection()
{
try
{
connection.Close();
return true;
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
return false;
}
}
//Insert statement
public void Insert()
{
string query = "INSERT INTO Orders (name, age) VALUES('John Smith', '33')";
//open connection
if (this.OpenConnection() == true)
{
//create command and assign the query and connection from the constructor
MySqlCommand cmd = new MySqlCommand(query, connection);
//Execute command
cmd.ExecuteNonQuery();
//close connection
this.CloseConnection();
}
}
can any one of you please tell me what to type in "server" string i tried server ip but don't work
can any one of you please tell me what to type in "server" string i tried server ip but don't work

Kunal VaishyaRank #990 · 2K reputationPosted Apr 29, 2014, 4:34 AM EDT
Use IP Address instead of Server Name and try.
Nick77 reputationPosted Apr 29, 2014, 6:36 AM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 29, 2014, 6:49 AM EDT
Nick77 reputationPosted Apr 29, 2014, 7:00 AM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 29, 2014, 7:14 AM EDT
Do you know whether the id column is generated automatically? If it isn't then you'll need to pass an INT value for that if it can't be NULL.
Nick77 reputationPosted Apr 29, 2014, 7:25 AM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 29, 2014, 7:30 AM EDT
Have you tried reading data from the database using the same set up rather than writing to it?
Nick77 reputationPosted Apr 29, 2014, 8:33 AM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 29, 2014, 4:10 PM EDT
Sanjay KumarRank #561 · 4.3K reputationPosted Apr 30, 2014, 12:34 AM EDT
try this
https://www.connectionstrings.com/mysql/
http://stackoverflow.com/questions/10065259/connection-string-for-mysql-database-on-webserver-having-shared-ip-address-c-s
http://www.c-sharpcorner.com/UploadFile/47548d/install-mysql-connector-in-visual-studio-2012/
http://www.c-sharpcorner.com/UploadFile/47548d/how-to-retrieve-data-from-mysql-database-in-C-Sharp/
http://www.c-sharpcorner.com/UploadFile/47548d/simple-insert-select-update-and-delete-in-Asp-Net-using-mysq/
Anupam SinghRank #643 · 3.7K reputationPosted May 12, 2014, 2:58 AM EDT
To access MySql DB from Internet there are two important thing you have to configure
1. Open the port 3306(which is default port for MySQL) for incoming requests on the server.
2. Access DB using TCP\IP (IP address).
sudipta sanyalRank #1,945 · 753 reputationPosted May 13, 2014, 1:28 AM EDT
go throw
http://sudiptasanyal.blogspot.in/2011/03/how-you-connect-mysql-databse-with.html