'Soft back key pressed
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
Dim KillApp As Int
If KeyCode = KeyCodes.KEYCODE_BACK Then
KillApp = Msgbox2("Exit Simply Invoice AE?" ,"Exit?", "Yes", "", "No", Null)
If KillApp = DialogResponse.POSITIVE Then
MySQL.CloseDatabase
ExitApplication
Return False
Else
Return True
End If
End If
Return True
End Sub
Hello @answer,
I believe that the MySQL server will automatically close the connection if there is no activity with that said connection in a given time.
My app will have multiple activities. Do I need to create a new Database object in each activity ? While using RDC I was using different DBRequestManager objects for each activity. I did so because, the JobDone was in one of the activities and calling RDC query from another activity had some unexpected results. As I am a newbie I haven't tried using a service module to cater to each activities Database manipulation requests. Even now, I don't know how to handle this with a service module and avoid using multiple instances of the connection object to the same database.
'Some sub of yours
Sub Test_Connection
MySQL.check_connection
End Sub
Sub Query_Status(Connected As Boolean, ReConnecting As Boolean, RetriesLeft As Int)
If Connected = False then MySQL.Initialize("Query", DBHost, DBUser, UsrPW, DBName)
End Sub
Not all Providers allow Access to Databases from "Outside". You need to ask your Provider if they allow remote Access to the DB.Why i cant connect to online MySQL using this library?
No. The Lib CAN connect to any MySQL Database WHEN THE DATABASE IS ACCESSIBLE FROM OUTSIDE. I´´m using the Lib with my Databases hosted on my Webside but i´m allowed to do so.Is this for local Connection only?
You are right. There was an error in both msMySQL and msMariaDB libs. Will update new version in a few minutes on my Dropbox folderi'm executing batch with MSMySQL, but i haven't a good result. I lost the first and de the last record, but this records are in the list.
** Activity (main) Create, isFirst = true **
Raising.. anser_status
Connected to Database
** Activity (main) Resume **
Reached CheckLogin Sub. About to execute Login Query
lib:queryasync()
Reached QueryResult Sub. About to execute Login Query
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
MySQL Database not connected!
ReConnecting
java.lang.NullPointerException
at de.donmanfred.b4a.MariaDB.auto_reconnect(MariaDB.java:1092)
at de.donmanfred.b4a.MariaDB.check_connection(MariaDB.java:1137)
at com.popularjcb.emptool.main._activity_resume(main.java:408)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at com.popularjcb.emptool.main.afterFirstLayout(main.java:106)
at com.popularjcb.emptool.main.access$100(main.java:17)
at com.popularjcb.emptool.main$WaitForLayout.run(main.java:78)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException
Sub Process_Globals
Dim cDbIP As String :cDbIP="192.168.x.xxx"
Dim cDataBase As String :cDataBase="MyDbName"
Dim cDbUserName As String :cDbUserName="MyUserName"
Dim cDbPassword As String :cDbPassword="MyPassword"
End Sub
Sub Globals
Private oConnection As MSMaria
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Try
oConnection.Initialize("anser",cDbIP,cDbUserName,cDbPassword,cDataBase)
Catch
Msgbox("Unable to connect to the server","Server unavailable")
End Try
End If
End Sub
Sub Activity_Resume
oConnection.check_connection
'I tried the following line too, unfortunately no difference
'oConnection.check_connection2
End Sub
Sub Activity_Pause (UserClosed As Boolean)
oConnection.CloseDatabase
End Sub
Sub anser_Status(Connected As Boolean, ReConnecting As Boolean, RetriesLeft As Int)
If Connected = False Then
ToastMessageShow("Connection was Lost. Re-establishing connection now", True)
oConnection.Initialize("anser",cDbIP,cDbUserName,cDbPassword,cDataBase)
End If
End Sub
Sub CheckLogin(cUserName As String, cPassword As String)
Dim cSql As String
cSql = "SELECT user_id,username FROM users WHERE username = '"&cUserName&"' AND password = '"&cPassword&"';"
Log( "Reached CheckLogin Sub. About to execute Login Query")
oConnection.QueryASync(cSql,"LoginQuery")
End Sub
Sub anser_QueryResult(Data As List, Meta As Map)
Log( "Reached QueryResult Sub. About to execute Login Query")
' Login Process
If Meta.Get("TaskID") = "LoginQuery" Then
.....
End If
End Sub
Basically you should work like this:
- Initialize on Activity_create
- Checkconnection on Activity_Resume
- CloseDatabase on Activity_Pause
If you are working with multiple activities then this apply to all activities.
If you are then working a longer time in one activity; maybe with a longer timerout (>5 min) then - in background - the connection will be closed from the server. If you then do another call then the lib will get an connection lost and will try to reconnect and then executing your query... The first query after such time out period can be last longer cause the lib first needs to get the connectionlost and to reconnect.
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Try
oConnection.Initialize("anser",cDbIP,cDbUserName,cDbPassword,cDataBase)
Catch
Msgbox("Unable to connect to the server","Server unavailable")
End Try
End If
End Sub
Sub Activity_Create(FirstTime As Boolean)
oConnection.Initialize("anser",cDbIP,cDbUserName,cDbPassword,cDataBase)
End Sub
Have you tried to add a ":[portno]" to the hostname?f my database runs on a different port (other than the regular port 3306 ), then how do I specify the MySQL Database port using this lib?
Yes. Providing port number along with domain name serves the purpose. It is workingHave you tried to add a ":[portno]" to the hostname?
host: testserver
->
Host: testserver:1234
** Activity (main) Create, isFirst = true **
Raising.. anser_status
Connected to Database
** Activity (main) Resume **
lib:executeasync()
lib:queryasync()
Reached QueryResult Sub. About to execute Login Query
Reached CheckLogin Sub. About to execute Login Query
lib:queryasync()
Reached CheckLogin Sub. About to execute Login Query
lib:queryasync()
Reached CheckLogin Sub. About to execute Login Query
lib:queryasync()
Reached CheckLogin Sub. About to execute Login Query
lib:queryasync()
SqlException: java.sql.SQLNonTransientConnectionException: Could not read resultset: unexpected end of stream, read 0bytes from 4
SqlException: java.sql.SQLNonTransientConnectionException: Could not read resultset: unexpected end of stream, read 0bytes from 4
SqlException: java.sql.SQLNonTransientConnectionException: Could not send query: sendto failed: EPIPE (Broken pipe)
SqlException: java.sql.SQLNonTransientConnectionException: Could not read resultset: unexpected end of stream, read 0bytes from 4
Reached QueryResult Sub. About to execute Login Query
main_anser_queryresult (java line: 421)
java.lang.NullPointerException
at com.popularjcb.emptool.main._anser_queryresult(main.java:421)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
~e: at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at anywheresoftware.b4a.BA$3.run(BA.java:332)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException