Welcome aboard! We are happy you are here and wish you good net-raft!
// add reference MySgl.Data
using System;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string connetionString = null;
MySqlConnection cnn ;
connetionString = "server=localhost;database=testDB;uid=root;pwd=xxx;";
cnn = new MySqlConnection(connetionString);
try
{
cnn.Open();
MessageBox.Show ("The connection is open!");
cnn.Close();
}
catch (Exception ex)
{
MessageBox.Show("The connection is refused!");
}
}
}
}
// connectionstring for TCP port
myConnectionString="Server=myServerAddress;Port=xxx;Database=testDB;Uid=root;Pwd=xxx;";
The most helpful C# solutions