Connecting to MySQL from PC
-
Hi, Just wondering... I downloaded the MySQLConnection library for VS. I'm using the code below to try and connect to a MySQL database on my webpage. It's not working though :( Anyone tried doing this before?
string server = "Server=http://www.somepage.org.nz;Database=somedatabase;Uid=myusername;Pwd=mypassword"; MySqlConnection con = null; try { con = new MySqlConnection(server); con.Open(); this.label1.Text = con.State.ToString(); } catch (Exception ex) { this.label1.Text = ex.Message; }
Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen
-
Hi, Just wondering... I downloaded the MySQLConnection library for VS. I'm using the code below to try and connect to a MySQL database on my webpage. It's not working though :( Anyone tried doing this before?
string server = "Server=http://www.somepage.org.nz;Database=somedatabase;Uid=myusername;Pwd=mypassword"; MySqlConnection con = null; try { con = new MySqlConnection(server); con.Open(); this.label1.Text = con.State.ToString(); } catch (Exception ex) { this.label1.Text = ex.Message; }
Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen
-
Hi, Just wondering... I downloaded the MySQLConnection library for VS. I'm using the code below to try and connect to a MySQL database on my webpage. It's not working though :( Anyone tried doing this before?
string server = "Server=http://www.somepage.org.nz;Database=somedatabase;Uid=myusername;Pwd=mypassword"; MySqlConnection con = null; try { con = new MySqlConnection(server); con.Open(); this.label1.Text = con.State.ToString(); } catch (Exception ex) { this.label1.Text = ex.Message; }
Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen
Hi, 1) First you need to add reference MySql.Data to your application. 2) Then //create a new mysqlconnection MySqlConnection mycon = new MySqlConnection("datasource=localhost;username=root;password=pwd;database=project"); //create a mysql DataAdapter MySqlDataAdapter myadp = new MySqlDataAdapter("select * from FAB", mycon); //create a dataset DataSet myds = new DataSet(); //now fill and bind the DataGrid myadp.Fill(myds, "empinfo"); dataGridView1.DataSource = myds.Tables["empinfo"].DefaultView; I have used with windows application. Try this. Regards, Subbu
-
Hi, Just wondering... I downloaded the MySQLConnection library for VS. I'm using the code below to try and connect to a MySQL database on my webpage. It's not working though :( Anyone tried doing this before?
string server = "Server=http://www.somepage.org.nz;Database=somedatabase;Uid=myusername;Pwd=mypassword"; MySqlConnection con = null; try { con = new MySqlConnection(server); con.Open(); this.label1.Text = con.State.ToString(); } catch (Exception ex) { this.label1.Text = ex.Message; }
Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen
MarkBrock wrote:
string server = "Server=http://www.somepage.org.nz;
That's not going to work. You cannot access a database over the HTTP protocol. Your corrected string should look more like:
Server=someSqlServer.somepage.org.nz;
But, that's not likely to work either. Either the MySQL server has to be exposed directly to the Internet (a REALLY STUPID thing to do), or that site has to expose some other method of interaction with the database, such as a Web Service.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
MarkBrock wrote:
string server = "Server=http://www.somepage.org.nz;
That's not going to work. You cannot access a database over the HTTP protocol. Your corrected string should look more like:
Server=someSqlServer.somepage.org.nz;
But, that's not likely to work either. Either the MySQL server has to be exposed directly to the Internet (a REALLY STUPID thing to do), or that site has to expose some other method of interaction with the database, such as a Web Service.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...Dave Kreskowiak wrote:
...exposed directly to the Internet (a REALLY STUPID thing to do)...
Check out the CodeProject forum Guidelines[^] The original soapbox 1.0 is back![^]
-
MarkBrock wrote:
string server = "Server=http://www.somepage.org.nz;
That's not going to work. You cannot access a database over the HTTP protocol. Your corrected string should look more like:
Server=someSqlServer.somepage.org.nz;
But, that's not likely to work either. Either the MySQL server has to be exposed directly to the Internet (a REALLY STUPID thing to do), or that site has to expose some other method of interaction with the database, such as a Web Service.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...