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.
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