Question connect to server Mariadb online

n3wkid

Member
Joined
Sep 14, 2014
Messages
7
Programming Experience
3-5
Dear Master,

I would like to ask how to connect(code) to server mariadb online using interface C#. assume here is connection using internet. interface c# as FE and BE is Server MariaDB. Thanks for your advice.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,136
Location
Sydney, Australia
Programming Experience
10+
Apparently, it is recommended that you use Connector/Net from MySQL to connect to MariaDB. I've never used MariaDB or even MySQL all that much but it looks like you use the same format for the connection string.
 

n3wkid

Member
Joined
Sep 14, 2014
Messages
7
Programming Experience
3-5
Thank for you fast response.

I have installed on my laptop MySql Connector two month ago and normally I have test to connect to localhost mysql that success using C# as interface and nothing found error.
with condition : attached references "MySQL.data" on Visual studio 2012. and server still only localhost(nothing need the internet line or needn't LAN IP)

Now the other situation, I have one server and there installed mariadb server(centOS 7) on LAN and there assigned IP for this server of course and also assigned IP for client.
in the meantime, Ping from client to server is good.
so when I use old code previously have test on localhost, The warning message I found , "unable to connect to any of the specified mysql host"
any idea for connection c# as interface to mariaDB server LAN
 

n3wkid

Member
Joined
Sep 14, 2014
Messages
7
Programming Experience
3-5
Ok sir, I will go to the site, everything happen, I will come back.
Thanks so much.
 

n3wkid

Member
Joined
Sep 14, 2014
Messages
7
Programming Experience
3-5
Dear Master,

Connecting string that i used is

string conn = "Server=192.168.56.102;protocol=3306;UID=root;PWD=1234;Database=mydb";

MySql.Data.MySqlClient.MySqlConnection cn = new MySql.Data.MySqlClient.MySqlConnection();
cn.ConnectionString = conn;



but with code above, I can't connect to server CentOS 7 "MariaDB Server". the message error unable connect to any mysql. and after i disable firewall on each machine, the error message is " authenticate for user ....."

note :
- I have disable all firewall On client and server to take a look "connect or not"
- I used code with php as web application interface, the connection is established and success.
- VS 2012 C#, connector using mysql-connector net 6.8.3
- Connection only use LAN(peer to peer)
-


please help me.
 

n3wkid

Member
Joined
Sep 14, 2014
Messages
7
Programming Experience
3-5
sorry sir, I amend it, this is only wrong type...

anyway, I have change to
"port:3306"
, still can not make change(cant connect)...
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,136
Location
Sydney, Australia
Programming Experience
10+
sorry sir, I amend it, this is only wrong type...

anyway, I have change to , still can not make change(cant connect)...
Why did you now change the equals (=) to a colon :))? Show us the exact code you're using and tell us exactly what happens. If there's an exception thrown when you try to connect then give us the exact error message. Don't be vague because we only know what you tell us so you have to tell us everything that's relevant and precisely.
 

n3wkid

Member
Joined
Sep 14, 2014
Messages
7
Programming Experience
3-5
Dear Master,

Here I display my code to use to connect to server CentOS 7. VS 2012 C# only Front End interface

using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            
            
             //String connectingstring = "Server=127.0.0.1;Port=3306;UID=root;PWD=123;Database=test";
            //-> code previously above for using connect to localhost(PC of standalone) and there nothing problem , then connection was success full..
             
            String connectingstring = "Server=192.168.0.2;Port=3306;UID=root;PWD=123;Database=test"; 
           //--> this is I used to connect to Server MariaDB(CentOS) via LAN and could not to be connected.


            MySqlConnection conn = new MySqlConnection(connectingstring);
            try
            {
                conn.Open();
                MessageBox.Show("Connected successfull");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}



note:
-I have upgrade to mysql-connector net-6.9.3.
- VS 2012 C#

please advice me.thanks
 
Last edited by a moderator:

n3wkid

Member
Joined
Sep 14, 2014
Messages
7
Programming Experience
3-5
Dear Master,

Solved..the problem came from on server mariadb configuration. from the first I could have imagine this problem come from my configure server mariadb on CentOS.
wrong configuration from server such as firewall configuration does not exact, privileges on mariadb server,that make connection could not be established.
So I think closed this thread.
anyway many thank to Mr. JohnH, Mr. jmcilhinney that their response.

thanks so much.
 
Top Bottom