skip to Main Content

I am developing a Flutter application in android studio. In a separate ‘DbHelper.dart’ file, the following code connects to Azure MySQL server.
DbHelper.dart:

import 'package:mysql1/mysql1.dart';


void main() async {
       final connSettings = ConnectionSettings(
       host: 'hostname.mysql.database.azure.com',
       port: 3306,
       user: 'user',
       password: 'password',
       db: 'db',
     );
     final conn = await MySqlConnection.connect(connSettings);
}

I want to link it in my app by adding this link to my Flutter ‘main.dart’ file.
Future<void> fetchUserInfo() async {...

But I am getting the following error:
ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: SocketException: Connection timed out, ...

Even though I give more than 15 minutes timeout, the same error still occurs.
timeout: const Duration(minutes: 15),

Although it runs in the dart file it doesn’t work when I debug it for the app.
How can I connect Azure MySQL server from my Flutter application. I want to send a query and get the results for my Flutter app.

2

Answers


  1. Chosen as BEST ANSWER

    I have solved the issue. The time-out error is caused by the emulator not being up to date or flutter android studio configuration:

    flutter config --android-studio-dir="C:/Program Files/Android/Android Studio"
    

  2. It is probably that you are not able to connect to the server because port 3306 is not open.

    To open the port see: https://serverfault.com/questions/549779/how-to-enable-remote-access-to-a-mysql-server-on-an-azure-virtual-machine

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search