Connection refused in .Net Core and MySql

Dung Do Tien Mar 05 2022 592

Hello guys, I have created a project with Asp.Net 5 with FE Core and MySql. I also created a project test with NUnit. Everything still works very well on local, all test cases passed. But when I CI/CD in GitHub and add automation test with command:

Connection refused in .Net Core and MySql

When running CI in Github, I got an exception throw ExtendedSocketException : Connection refused

Error Message:
   System.AggregateException : One or more errors occurred. (Connection refused
  ----> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException : Connection refused
  Stack Trace:
     at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout)
   at MySql.Data.Common.StreamCreator.GetTcpStream(MySqlConnectionStringBuilder settings, MyNetworkStream& networkStream)
   at MySql.Data.Common.StreamCreator.GetStream(MySqlConnectionStringBuilder settings, MyNetworkStream& networkStream)
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at MySql.Data.MySqlClient.MySqlConnection.<OpenAsync>b__75_0()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj)

I have a public DB connection and I changed it in appsetting.json file. 

What's that mean? and how can I fix it?

Have 1 answer(s) found.
  • T

    Tran Quang Hung Mar 05 2022

    I sure in your project still has connection string to server local You can search "" in your solution and change it to public string connect.

    If you use FE, maybe you can open your DBContext and check OnConfiguring() method, you have to change or comment connectstring here:

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        if (!optionsBuilder.IsConfigured)

    I hope it helpful for you!!

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close