Android Question MsMySQL - Unable to connect


Well-Known Member
Licensed User
Longtime User

My MySQL database is accessible from "outside". All my other applications (VB and PHP) are able to connect to this database. Unfortunately from B4A, it is saying communication failure and the app is not getting connected to the DB

Even the firewall is OFF on the PC running the Database. I am unable to identify the reason.

The version of the LIB is 1.09

Here is the code that I use, Please note that I am using a Service

#Region  Service Attributes
    #StartAtBoot: False

#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    ' Database related Global Values
    Dim cDbIP As String :cDbIP=""
    Dim cDataBase As String :cDataBase="MyDbName"
    Dim cDbUserName As String :cDbUserName="root"
    Dim cDbPassword As String :cDbPassword="password"

    Dim oCn As MySQL
End Sub

Sub Service_Create
    Log("Inside Service Create")

        Log("Log : Connected")
        Log("Log : Error could not connect")
    End Try

End Sub

Sub Service_Start (StartingIntent As Intent)
    Log("Inside Service start")
End Sub

Sub Service_Destroy
    Log("Inside Service Destroy")
End Sub

Sub ExecQuery(Parameters As Map)

    'This is how other Activity Modules call this Service
'CallSubDelayed2(DbService,"ExecQuery",CreateMap("Sql":cSql,"TaskID":"GetUsrName","CallBackModuleName":"Main","CallBackSubName":"MyFunction") )
    Log("Inside ExecQuery")
    Dim cSql As String    = Parameters.Get("Sql")
    Dim cTaskID As String = Parameters.Get("TaskID")

    Dim MyArray(2) As String

    'Adding the Task ID to the List
End Sub

Sub MyDB_QueryResult(Data As List, Meta As Map)
    Log("inside MyDB_QueryResult")

End Sub

Sub MyDB_Status(Connected As Boolean, ReConnecting As Boolean, RetriesLeft As Int)
   Log("Connected = " & Connected)
   Log("ReConnecting = " & ReConnecting)
   Log("RetriesLeft = " & RetriesLeft)
End Sub

This is waht it shows on my Log.

LogCat connected to: 83f0485a4b484c53
--------- beginning of main
--------- beginning of system
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (dbservice) Create **
Inside Service Create
Can not connect to the MySQL Database Server. Please check your configuration.
Username: root
Error: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Raising.. mydb_status
not Connected to Database
Log : Connected
** Service (dbservice) Start **
Inside Service start
MySQL Database not connected!
Connected = false
ReConnecting = false
RetriesLeft = 0
Inside ExecQuery
MySQL Database not connected!
lib:Exception:java.lang.NullPointerException: Attempt to invoke interface method 'java.sql.Statement java.sql.Connection.createStatement()' on a null object reference
SqlException: java.lang.NullPointerException: Attempt to invoke interface method 'java.sql.Statement java.sql.Connection.createStatement()' on a null object reference
inside MyDB_QueryResult
** Service (newinst2) Create **
---- AppUpdating.NewInst2: service created
** Service (newinst2) Start **
-- AppUpdating.NewInst2: processing service_start
** Activity (main) Pause, UserClosed = false **

Is there anything particularly that I should check ? This database is on a LAN. The firewall is disabled in the PC to ensure that it's not the firewall that is causing this issue. THis database is accessible from other PC's through HeidiSQL and other Applications. Wondering what is the cause.

Any help will be appreciated.

Last edited:


Licensed User
Longtime User
Looks like the Host cannot be reached or does not respond.

Maybe you are using another port on the mysql server running at this ip. Defult is 3306

The Device running the App is in the same Network?
Last edited:
Upvote 0


Well-Known Member
Licensed User
Longtime User

Instead of
IT should be

ie the StrictMode should be True
Upvote 0