mysql1_dart icon indicating copy to clipboard operation
mysql1_dart copied to clipboard

SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 35396

Open dhruv048 opened this issue 3 years ago • 8 comments

Tried sql for the first time but i am getting this error SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 35396

my code: var settings = new ConnectionSettings( host: 'localhost', port: 3306, user: 'flutter_admin', password: 'flutter_admin_password', db: 'flutter_admin' ); final conn =await MySqlConnection.connect(settings);

var result = await conn.query(
    'insert into location (id, live_location) values (?, ?)',
    ['Bob', 25]);
print('Inserted row id=${result.insertId}');

please help me, Thanks

dhruv048 avatar Oct 12 '20 05:10 dhruv048

Hey guys!

I have the same error like @dhruv048. I found a different behaviour between simple dart-code (Package integrated in Console-App.) and flutter-code (Package integrated in Mobile-Application.). Also interesting: the port is incremented by 2 after retrying the connection.

ERROR-MESSAGE: https://hastebin.com/vagifadiva.yaml

Code is simplified.

FLUTTER-CODE-EXAMPLE (android: 10.0.15): https://hastebin.com/emolimaxal.java

DART-EXAMPLE: https://hastebin.com/fikoseyihi.js

I would be really thankful, if you can fix this error. The package is actually really fine.

julius-stuemmler avatar Dec 26 '20 20:12 julius-stuemmler

I found a solution on Stack Overflow that helped me with this problem. By replacing host: 'localhost' with host: '10.0.2.2' It seemed to work perfectly.

DansMatee avatar Feb 02 '21 06:02 DansMatee

@DansMatee

Yeah possible solution, but I'm still getting this error using a IP of a server, where mysql is installed. Do you have a solution or idea for that?

julius-stuemmler avatar Feb 02 '21 08:02 julius-stuemmler

replacing the host for "10.0.2.2" did the trick for me, another detail is that if you are getting a conection refused, despite you having no password just comment the password in ConnectionSettings

ItzcoR avatar Mar 14 '21 21:03 ItzcoR

I found a solution on Stack Overflow that helped me with this problem. By replacing host: 'localhost' with host: '10.0.2.2' It seemed to work perfectly.

thanks your solution is worked for me

Adil-Rangila avatar Jun 05 '21 09:06 Adil-Rangila

in my case , instead of local address , i use ethernet ip address ( wireless ) , my android emulator cant ping my local macbook.

yogithesymbian avatar Sep 12 '21 12:09 yogithesymbian

In case if you use Django as your backend, you need to run with python manage.py runserver your_ip:port. And replace your localhost IP address to Django ip address in flutter project if you are trying to run on an iPhone device.

bmpsst511 avatar Sep 25 '21 20:09 bmpsst511