Hi,
It's going to be difficult for me to do a working example of this issue, but I try to ask the question first and if needed I'll do a working example.
The problem I get, is when I connect to a remote SQL database, if I do too many "SQL.ExecQueryAsync", I get this "Operation not allowed after ResultSet closed" error:
It happens with this "LoadProject_QueryComplete" sub:
The weird thing here is that the error is not caught either by the "If Success..." nor by the "Try / Catch" and actually happens right when calling the "Do While Crsr.NextRow" loop.
The code doesn't crash if I use ExecQuery2 instead of ExecQueryAsync.
The error says that my result set is closed, but I close it after the loop. The only issue I can see, is that I have many asyncQueries happening in background, but all the others work as expected.
Any help would greatly be appreciated!
Regards
Jmon.
It's going to be difficult for me to do a working example of this issue, but I try to ask the question first and if needed I'll do a working example.
The problem I get, is when I connect to a remote SQL database, if I do too many "SQL.ExecQueryAsync", I get this "Operation not allowed after ResultSet closed" error:
pageproject._loadproject_querycomplete (java line: 262)
java.sql.SQLException: Operation not allowed after ResultSet closed
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:800)
at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:6982)
at anywheresoftware.b4j.objects.SQL$ResultSetWrapper.NextRow(SQL.java:389)
at com.xxxx.xxxx.pageproject._loadproject_querycomplete(pageproject.java:262)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.BA$3.run(BA.java:178)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/12350821.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/7135120.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/24247422.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
It happens with this "LoadProject_QueryComplete" sub:
B4X:
Private Sub LoadProject(id As Int)
currentProjectId = id
'Get the notes:
Dim s As StringBuilder : s.Initialize
s.Append("SELECT note_message, note_user_id, note_timestamp, note_project_id ")
s.Append("FROM project_notes ")
s.Append("WHERE note_project_id = ? ")
s.Append("ORDER BY note_timestamp ")
s.Append(";")
If Main.SQL.isInitialized = False Then Main.ConnectToSQL
Main.SQL.ExecQueryAsync("LoadProject", s, Array(currentProjectId))
End Sub
Private Sub LoadProject_QueryComplete (Success As Boolean, Crsr As ResultSet)
If Success Then
lvNotes.Items.Clear
Do While Crsr.NextRow '<--- CRASH happens HERE!
Try
Dim User As ChatUser = UserUtils.FindUserByUniqueId(Crsr.GetInt("note_user_id"))
If User <> Null Then
Dim cm As ChatMessage
cm.Initialize(lvNotes)
cm.Image = User.Image40
cm.UserName = User.NickName
cm.Message = Crsr.GetString("note_message")
If User.UniqueId = Main.USER_MYSELF.UniqueId Then
cm.Color = Main.STYLE_COLOR_MSG_FROM_ME
Else
cm.color = Main.STYLE_COLOR_MSG_FROM_OTHERS
End If
cm.setDateTime(Crsr.GetLong("note_timestamp"))
cm.Show
End If
Catch
Log(LastException.Message)
End Try
Loop
Crsr.Close
Else
If LastException.isInitialized Then Debug.Write("PageProjects\LoadProject_QueryComplete", "SQL Exception: " & CRLF & LastException.Message, Debug.VERBOSE_EXCEPTION)
End If
End Sub
The weird thing here is that the error is not caught either by the "If Success..." nor by the "Try / Catch" and actually happens right when calling the "Do While Crsr.NextRow" loop.
The code doesn't crash if I use ExecQuery2 instead of ExecQueryAsync.
The error says that my result set is closed, but I close it after the loop. The only issue I can see, is that I have many asyncQueries happening in background, but all the others work as expected.
Any help would greatly be appreciated!
Regards
Jmon.