Error connecting to database using Entity Framework

Asked

Viewed 161 times

0

I am creating a WPF application, and decided to use the Entityframework to perform operations in my bank. I created a data model from an existing database in my Mysql Workbench, and the process was executed correctly, exporting all tables and generating a context for them.

However, when you want to perform any kind of operation in the application, such as entering data into a table, for example, the program hangs and is automatically terminated (without giving any error message). And the data is also not being stored in the database.

The code that is giving error is as follows:

private void Button_Click(object sender, RoutedEventArgs e)
    {
        using (maisfilmesEntities ctx = new maisfilmesEntities())
        {
            usuario u = new usuario
            {
                login = "Teste",
                senha = "teste"
            };
            ctx.usuario.Add(u);
            ctx.SaveChanges();
        }
    }

The exceptions generated by:

MySql.Data.MySqlClient.MySqlException (0x80004005): The host localhost does not support SSL connections.
em MySql.Data.MySqlClient.NativeDriver.Open()
em MySql.Data.MySqlClient.Driver.Open()
em MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
em MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
em MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
em MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
em MySql.Data.MySqlClient.MySqlPool.GetConnection()
em MySql.Data.MySqlClient.MySqlConnection.Open()
em System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher <Open>b__36(DbConnection t, DbConnectionInterceptionContext c)

Error caught with Try/catch:

The underlying Provider failed on Open.

  • I edited the post with the complete exception.

  • i am using mysql in a project, to use I had to install in my project these packages, here and here

1 answer

0

I believe you just need to add SslMode=none in your string Connection.

Take an example:

string connectionString = "ServerDoMeuBD;Database=MeuBD;Uid=Usuario;Pwd=Senha;SslMode=none;";

Read more about the Mysql string Connection options here.

Browser other questions tagged

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