Click here to Skip to main content
15,885,748 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I have a working code in VS 15 asp.net MVC 5 of MySQL connection. when I am going to connect with the same code in Vs 19 Asp.net MVC Core 3.1 it gives an error

Here is my code

NuGet package (MySql.Data (8.0.26))

using System.Data;
using MySql.Data.MySqlClient;
DataSet DsLoc = new DataSet();
MySqlDataAdapter da;


public IActionResult Index()
{
    DataTable Dt = new DataTable();
    DsLoc.Clear();
    //MySqlConnection con = new MySqlConnection("server=localhost; User Id=root; password=1234; database=hrdb;");
    MySqlConnection con = new MySqlConnection("server=localhost;uid=root;pwd=1234;database=hrdb;");
    //MySqlConnection con = new MySqlConnection(SqlHelper.GetConnection());
    con.Open();
    da = new MySqlDataAdapter("select * from companymaster order by ID desc", con);
    da.Fill(DsLoc, "Master-INFO");
    Dt = DsLoc.Tables[0];
    con.Close();
    return View(Dt);
}


AND THIS IS THE ERROR

Inner Exception 1:
AggregateException: One or more errors occurred. (Unable to read data from the transport connection: An established connection was aborted by the software in your host machine..)

Inner Exception 2:
IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine..

Inner Exception 3:
SocketException: An established connection was aborted by the software in your host machine.


What I have tried:

I stop antivirus and firewall

I have added "SslMode=none" in my connection string

But Nothing work with VS 19 ASP.net MVC Core 31

Please Help Me to Fix This
Posted
Updated 18-Aug-21 0:09am

1 solution

The MySql.Data package has been buggy for a long time. The recommended "solution" is to switch to using the MySqlConnector package instead:
NuGet Gallery | MySqlConnector 1.3.11[^]
Migrating from Connector/NET - MySqlConnector[^]

Beyond that, there's a bug report from 2015 that looks like it could be related:
MySQL Bugs: #76597: Reading from stream failed[^]

And the MySQL docs have details on diagnosing communication failures like this:
MySQL :: MySQL 8.0 Reference Manual :: B.3.2.9 Communication Errors and Aborted Connections[^]
 
Share this answer
 
Comments
Asif 7969814 18-Aug-21 8:38am    
Thanks, A lot Richard

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900