tags:

views:

32

answers:

2

I cannot connect to MySQL it fails on line connection.Open(), is there something wrong with my code ?

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

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

        private void Form1_Load(object sender, EventArgs e)
        {

            string MyConString = "SERVER=localhost:3316;" +
                "DATABASE=mydb;" +
                "UID=user;" +
                "PASSWORD=password;";
            MySqlConnection connection = new MySqlConnection(MyConString);
            connection.Open();
            // ...
            connection.Close();

        }
    }
}
+2  A: 

You need to specify the Port as a separate argument in the connection string and it looks like the password key is "Pwd" instead of "Password".

See connectionstrings.com for help on the exact syntax.

Morten Mertner
I think you should be right, will try.
+2  A: 

this is the string format I use to connect via the MySql.Data.dll version 6.1.2.0

server={0};user id={1};password={2};database={3};port={4}

so your connection string should be

server=localhost;user id=user;password=password;database=mydb;port=3316

JDMX
thanks will try. I can't mark two answers as good one but I selected you as you have less points :)