0

I can't connect to a MySQL database, when I use the con.Open(); method it throws 3 exceptions detailing the same error: 'System.NullReferenceException'.

public void Initialize()
        {
            server = "127.0.0.1:3306";
            database = "reconocimiento";
            uid = "root";
            password = "root";
            string connectionString;
            connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";

        connection = new MySqlConnection(connectionString);

    }

       public bool OpenConnection()
        {
            try
            {
                connection.Open();
                // HERE IS WHERE THE EXCEPTION IS THROWN
                MessageBox.Show("Open");
                return true;
        }
            catch (MySqlException ex)
            {
                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;
            }
        }
Camilo Terevinto
  • 26,697
  • 6
  • 67
  • 99

0 Answers0