Connection refused 127.0.0.1:3306 in .Net Core and MySql

Dung Do Tien Mar 05 2022 46

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 127.0.0.1:3306 in .Net Core and MySql

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

Error Message:
   System.AggregateException : One or more errors occurred. (Connection refused 127.0.0.1:3306)
  ----> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException : Connection refused 127.0.0.1:3306
  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 127.0.0.1:3306. You can search "127.0.0.1:3306" 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)
        {
            optionsBuilder.UseMySQL("server=localhost:3306;uid=test_abc;pwd=1234;database=googlenotification");
        }
    }

    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