B4J Question SQL Connection and time out

Fabrice La

Active Member
Licensed User
Longtime User
I am using this code
B4X:
Try
        piConnexion.Enabled = True
        piConnexion.Visible = True
        MySql.Initialize2("com.mysql.jdbc.Driver", StringSql,BaseConnect.LoginB,BaseConnect.MDP)
    Catch
        piConnexion.Visible = False
        Msgbox.Show("Database connection settings not correct or timeOut. Please check et restart." & CRLF & LastException,"Database")
        MnDataBase_Action
        BtnQuit_Action
    End Try
But the form is freezed during the try connection; No Progressindicator show and no doevents

How I can show the Progressindicator during the Try ?
 

Fabrice La

Active Member
Licensed User
Longtime User
Thanks Erel ;)

Now my appli goes directly to the next step without the database connection, not good.
How to wait until the connection is timeout or success using the ProgressIndicator?
 
Upvote 0

Fabrice La

Active Member
Licensed User
Longtime User
yes I saw it but StartMessageLoop I can't use it "java.lang.RuntimeException: StartMessageLoop should only be called in non-UI applications."

My appli need to have the database connection to run (Login). how to wait untill the connection is done to be able to run login ?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is the code:
B4X:
Sub AppStart (Args() As String)
   sql1.InitializeAsync("sql1", "com.mysql.jdbc.Driver", _
     "jdbc:mysql://localhost/example?characterEncoding=utf8", "user", "password")
   StartMessageLoop 'only required in a console app
End Sub

Sub sql1_Ready (Success As Boolean)
   Log(Success)
   If Success = False Then
     Log(LastException)
     Return
   End If
   Dim rs As ResultSet = sql1.ExecQuery("SELECT table_name FROM information_schema.tables")
   Do While rs.NextRow
     Log(rs.GetString2(0))
   Loop
   rs.Close
End Sub
As written in the comment you only need to call StartMessageLoop in a console app. You need to handle the Ready event. It will be raised when the connection is ready.
 
Upvote 0

Fabrice La

Active Member
Licensed User
Longtime User
How to run an UI application and Non-UI Application (console) in the same time and share SQL connection ?
Do you have exemple ?
 
Upvote 0

Fabrice La

Active Member
Licensed User
Longtime User
I will start a new thread.

In my case it is the same.

My application try to connect to a remote Mysql and need to be connected to run (Login) means UI fx appli.

As always you have good solutions for question and I thank you for that.

The solution you provide is to use the InitializeAsync connection but this one use a Non-UI application. Related to this my concern is :

Is it possible to run UI and Non-UI in paralell and share SQL connection
 
Upvote 0
Top