dart-db / sqljocky5

MySQL driver for Dart
Other
40 stars 19 forks source link

Unhandled Exception: SocketException: Socket has been closed #33

Open ThitSarNyanLynn opened 5 years ago

ThitSarNyanLynn commented 5 years ago

When I run this simple codes, I found the following error log.

import 'dart:async';
import 'package:sqljocky5/sqljocky.dart';

Future<void> createTables(MySqlConnection conn) async {
  print("Creating tables ...");
  await conn.execute('CREATE TABLE people (id INTEGER NOT NULL auto_increment, '
      'name VARCHAR(255), '
      'age INTEGER, '
      'PRIMARY KEY (id))');
  await conn.execute('CREATE TABLE pets (id INTEGER NOT NULL auto_increment, '
      'name VARCHAR(255), '
      'species TEXT, '
      'owner_id INTEGER, '
      'PRIMARY KEY (id),'
      'FOREIGN KEY (owner_id) REFERENCES people (id))');
  print("Created table!");
}

main() async {
  var s = ConnectionSettings(
    user: "root",
    password: "",
    host: "192.168.1.3",
    port: 3306,
    db: "ppms",
  );

  // create a connection
  print("Opening connection ...");
  var conn = await MySqlConnection.connect(s);
  print("Opened connection!");

  await createTables(conn);

  await conn.close();
}

E/flutter ( 4153): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: SocketException: Socket has been closed E/flutter ( 4153): #0 Comm.connect (package:sqljocky5/comm/comm.dart:182:5) E/flutter ( 4153): E/flutter ( 4153): #1 MySqlConnectionImpl.connect (package:sqljocky5/connection/impl.dart:102:27) E/flutter ( 4153): E/flutter ( 4153): #2 MySqlConnection.connect (package:sqljocky5/connection/connection.dart:36:27) E/flutter ( 4153): #3 main (package:f_sqljocky_test/main.dart:28:36) E/flutter ( 4153): E/flutter ( 4153): #4 _runMainZoned.. (dart:ui/hooks.dart:189:25) E/flutter ( 4153): #5 _rootRun (dart:async/zone.dart:1124:13) E/flutter ( 4153): #6 _CustomZone.run (dart:async/zone.dart:1021:19) E/flutter ( 4153): #7 _runZoned (dart:async/zone.dart:1516:10) E/flutter ( 4153): #8 runZoned (dart:async/zone.dart:1500:12) E/flutter ( 4153): #9 _runMainZoned. (dart:ui/hooks.dart:180:5) E/flutter ( 4153): #10 _startIsolate. (dart:isolate/runtime/libisolate_patch.dart:300:19) E/flutter ( 4153): #11 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12) E/flutter ( 4153): Syncing files to device Android SDK built for x86...

tejainece commented 5 years ago

Thanks for reporting. I will try to reproduce it.

Are you trying to connect to mysql server on desktop from Flutter?

YuanTianyang commented 5 years ago

I had the same problem

jinfei commented 4 years ago

I had the same problem,too

ctcx commented 4 years ago

@tejainece when your password is error,you can catch this exception.

` file sqljocky5-2.2.1/lib/comm/buffered_socket.dart line 92: replace to onDataReady() } else if (event == RawSocketEvent.readClosed) { if (this.onClosed != null) { onDataReady(); //this.onClosed(); } }

` Run again after modification! I can catch this exception: Error 1045 (28000): Access denied for user 'user'@'ip' (using password: YES)

yusufnadar commented 3 years ago

Is there any solution?

4stern commented 3 years ago

this repo is down ..

mastgaurav001 commented 3 years ago

I also had the same problem.