Dear All,
I'm using the module jcfis-ng provided by DonManfred. Thank you to DonManfred!
I try to copy a SQL data base from a SMB2 share on my local network in order to use it in the app internally. Everything works fine in "Debug" mode, but in "Release" mode I'm receiving an exception:
The exception occurs in my resumable "sub SQLDBCopySMB". Here is a code snippet of it:
I added a couble of log-statements to watch where the exception comes up during release mode. The critical code line is identified:
This statement seems to be wrong (working in debug but not in release mode). The idea here is to get the size of the file to use it for a ProgressTimer (show percentage of copying process). The file name was explicitly set before SM2 initialization (very similar like this statement):
Does anybody know how I can get the file size in a correct way before starting the file copy process? Any help is appreciated.
Wosl
PS: in the first attempt I provide a snippet of the rather large app with the critical code but, if necessary, I could spend some time to isolate the issue in a separate test app.
I'm using the module jcfis-ng provided by DonManfred. Thank you to DonManfred!
I try to copy a SQL data base from a SMB2 share on my local network in order to use it in the app internally. Everything works fine in "Debug" mode, but in "Release" mode I'm receiving an exception:
B4X:
In SQLDBCopySMB: Before SMB initialisierung
In SQLDBCopySMB: After SMBClient_Copy_Resource
In SQLDBCopySMB: After Resource allocation
main$ResumableSub_SQLDBCopySMBresume (java line: 26734)
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1675)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:115)
at java.net.SocketOutputStream.write(SocketOutputStream.java:156)
at jcifs.smb.SmbTransportImpl.doSend(SmbTransportImpl.java:894)
at jcifs.util.transport.Transport.doSend(Transport.java:276)
at jcifs.util.transport.Transport.sendrecv(Transport.java:215)
at jcifs.smb.SmbTransportImpl.sendrecv(SmbTransportImpl.java:1005)
at jcifs.smb.SmbTransportImpl.send(SmbTransportImpl.java:1523)
at jcifs.smb.SmbSessionImpl.sessionSetupSMB2(SmbSessionImpl.java:549)
at jcifs.smb.SmbSessionImpl.sessionSetup(SmbSessionImpl.java:483)
at jcifs.smb.SmbSessionImpl.send(SmbSessionImpl.java:369)
at jcifs.smb.SmbSessionImpl.send(SmbSessionImpl.java:347)
at jcifs.smb.SmbTreeImpl.treeConnect(SmbTreeImpl.java:607)
at jcifs.smb.SmbTreeImpl.send(SmbTreeImpl.java:429)
at jcifs.smb.SmbTreeImpl.send(SmbTreeImpl.java:405)
at jcifs.smb.SmbTransportImpl.getDfsReferrals(SmbTransportImpl.java:1703)
at jcifs.smb.DfsImpl.getDcReferrals(DfsImpl.java:192)
at jcifs.smb.DfsImpl.getDc(DfsImpl.java:234)
at jcifs.smb.DfsImpl.getTrustedDomains(DfsImpl.java:112)
at jcifs.smb.DfsImpl.resolve(DfsImpl.java:347)
at jcifs.smb.DfsImpl.resolve(DfsImpl.java:321)
at jcifs.smb.SmbTreeConnection.connectHost(SmbTreeConnection.java:525)
at jcifs.smb.SmbTreeConnection.connectHost(SmbTreeConnection.java:484)
at jcifs.smb.SmbTreeConnection.connect(SmbTreeConnection.java:460)
at jcifs.smb.SmbTreeConnection.connectWrapException(SmbTreeConnection.java:421)
at jcifs.smb.SmbFile.ensureTreeConnected(SmbFile.java:551)
at jcifs.smb.SmbFile.length(SmbFile.java:1547)
at de.donmanfred.SMBFilewrapper.getlength(SMBFilewrapper.java:281)
at B4A.PVMonitoringNew.main$ResumableSub_SQLDBCopySMB.resume(main.java:26734)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:215)
at anywheresoftware.b4a.BA$2.run(BA.java:395)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:230)
at android.os.Looper.loop(Looper.java:319)
at android.app.ActivityThread.main(ActivityThread.java:8934)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:588)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
B4X:
'WOSL##################################################
Log ("In SQLDBCopySMB: Before SMB initialisierung")
'WOSL##################################################
'---------------------------------------------------------------------------
' Init SMB2 share (triggers event SMBClient_Resource)
'---------------------------------------------------------------------------
smbClient.Initialize("SMBClient_Copy", credentials.Domain, credentials.Username, credentials.Password, credentials.Share)
Wait for SMBClient_Copy_Resource (success As Boolean, smbobjres As Object, smbobj As Object, info As String)
If smbobjres <> Null And smbobj <> Null And info = "OK" Then
'WOSL##################################################
Log ("In SQLDBCopySMB: After SMBClient_Copy_Resource")
'WOSL##################################################
'---------------------------------------------------------------------------
' Copy SQL data base from SMB share
'---------------------------------------------------------------------------
Dim smbResources As SMBResource = smbobjres
Dim smbFiles As SMBFile = smbobj
'WOSL##################################################
Log ("In SQLDBCopySMB: After Resource allocation")
'WOSL##################################################
nSQLFileTotalSize = smbFiles.length
'WOSL##################################################
Log ("In SQLDBCopySMB: Before smbClient.Copy")
'WOSL##################################################
SQLFileTotalSize = nSQLFileTotalSize
smbClient.Copy (smbResources, File.DirInternal & "/" & cSQLDatabasePath, cSQLDatabaseName)
wait for SMBClient_Copy_CopyResult (success As Boolean, path As String, filename As String)
If success = True Then
MyLog ("SQL Datenbank '" & cSQLDatabaseName & "' vom SMB share erfolgreich nach '" & cSQLDatabasePath & "/" & cSQLDatabaseName & "' kopiert")
iReturn = 0
Else
MyLog ("Fehler: SQL Datenbank '" & cSQLDatabaseName & "' konnte NICHT vom SMB share kopiert werden")
iReturn = 2
End If
'WOSL##################################################
Log ("In SQLDBCopySMB: After SMBClient_Copy_CopyResult")
'WOSL##################################################
Sleep (0)
Else
iReturn = 1
End If
I added a couble of log-statements to watch where the exception comes up during release mode. The critical code line is identified:
B4X:
nSQLFileTotalSize = smbFiles.length
This statement seems to be wrong (working in debug but not in release mode). The idea here is to get the size of the file to use it for a ProgressTimer (show percentage of copying process). The file name was explicitly set before SM2 initialization (very similar like this statement):
B4X:
credentials.Share = "smb://192.168.178.1/HomeNet/TestDB/" & cSQLDatabaseName
Does anybody know how I can get the file size in a correct way before starting the file copy process? Any help is appreciated.
Wosl
PS: in the first attempt I provide a snippet of the rather large app with the critical code but, if necessary, I could spend some time to isolate the issue in a separate test app.