Problems connecting Mysql with Asp.net c#

Asked

Viewed 129 times

2

A small problem appeared, which in my old application worked normally.

My DAL Class, is not connecting in Mysql. Since all the connection parameters, I believe it is correct.

inserir a descrição da imagem aqui

My DAL who makes the connection.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Geax1.Model;
using MySql.Data;
using MySql.Data.MySqlClient;


namespace Geax1.DAL
{
   public class VeiculosDAL
   {
    public static void cadastra(_Veiculos obj)
    {
        using (var conn = new MySqlConnection("server=127.0.0.1;Database=xpto;User ID=root;Password='';"))
        {
            try
            {
                conn.Open();
                String InsertVeiculos = ("INSERT INTO tab_veiculo (placa,quilometragem,cor,tipo,ano,chassi,modelo) VALUES(@placa, @cor, @tipo, @ano, @chassi, @modelo)");

                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = InsertVeiculos;
                cmd.Connection = conn;
                cmd.Parameters.AddWithValue("@placa", obj.Placa1);
                cmd.Parameters.AddWithValue("@quilometragem", obj.Quilometragem1);
                cmd.Parameters.AddWithValue("@cor", obj.Cor1);
                cmd.Parameters.AddWithValue("@tipo", obj.Tipo1);
                cmd.Parameters.AddWithValue("@ano", obj.Ano1);
                cmd.Parameters.AddWithValue("@chassi", obj.Chassi1);
                cmd.Parameters.AddWithValue("@modelo", obj.Modelo1);
                cmd.ExecuteNonQuery();

            }
            catch (Exception e)
            {
                throw e;
            }
        }
    }
}

}

Note: My WAMP is on.

  • Check it out: https://github.com/brunoocasali/DataRepository is a repository to help you write these connection classes with the database in a simpler way:D

1 answer

2


Permission is missing, no matter how root the user is:

Perform the following:

CREATE USER 'usuario'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'usuario'@'localhost' WITH GRANT OPTION;
CREATE USER 'username'@'%' IDENTIFIED BY 'senha';
GRANT ALL PRIVILEGES ON *.* TO 'usuario'@'%' WITH GRANT OPTION;

Restart the WAMP.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.