Android Question SQLiteException: error code 8: attempt to write a readonly database

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi all.

Never seen this error before.

B4X:
 net.sqlcipher.database.SQLiteException: error code 8: attempt to write a readonly database

This is a code of the syb where this error happened


B4X:
Private Sub SaveReult(root As List) As Boolean
  
    Try
      

        Dim TransferResult As Int
        Dim ErrorStr As String, Result As String
        Dim ClientID As Int
        Dim PAID As Int
        Dim VitalName,VitalShortName As String,VitalID As Int
        Dim MonitorStatus As Boolean,TriggerStatus As Boolean,ToNurseSupervisor As Boolean,ToPCP,ToClient As Boolean
        Dim TriggerMinimum,TriggerMaximum As Double
        Dim MySQL As String
        Dim CurrentProviderID As Int
      
        MySQL="delete from tblClientVitalsSettings where ProviderID=?"
        SQL1.ExecNonQuery2(MySQL,Array As String(Main.ProviderID))
      
        For Each colroot As Map In root
      
            TransferResult=colroot.get("TransferResult")
            ErrorStr=colroot.Get("ErrorStr")
            Result=colroot.Get("Result")
      
            MsgStr=""
            IsError=False

            If TransferResult<>3 Then
                ProgressDialogHide
              
                MsgStr="Client Vitals Settings List has failed " & CRLF & "Error:" & ErrorStr & CRLF & "Result:" & Result & CRLF & " Check and try again"
                Return False
          
            Else If TransferResult=3 And Result<>"Ok" Then
                ProgressDialogHide
              
                MsgStr="Client Vitals Settings List has failed " & CRLF & "Error:" & Result  & CRLF & " Check and try again"
                Return False
          
            End If
      
      
            ClientID=colroot.Get("ClientID")
            PAID=colroot.get("PAID")
            VitalID=colroot.Get("VitalID")
            VitalName=colroot.Get("VitalName")
            VitalShortName=colroot.Get("VitalShortName")
            MonitorStatus=colroot.Get("MonitorStatus")
            TriggerStatus=colroot.Get("TriggerStatus")
            TriggerMinimum=colroot.Get("TriggerMinimum")
            TriggerMaximum=colroot.Get("TriggerMaximum")
            ToNurseSupervisor=colroot.Get("ToNurseSupervisor")
            ToPCP=colroot.Get("ToPCP")
            ToClient=colroot.Get("ToClient")
          
            CurrentProviderID=colroot.Get("ProviderID")
          
              
            MySQL="insert into tblClientVitalsSettings(ClientID,PAID,VitalName,MonitorStatus,TriggerStatus,TriggerMinimum, TriggerMaximum, ToNurseSupervisor,ToPCP,ProviderID,VitalID,VitalShortName,ToClient) "
            MySQL=MySQL & "values(?,?,?,?,?,?,?,?,?,?,?,?,?)"
          
            SQL1.ExecNonQuery2(MySQL,Array As String(ClientID,PAID,VitalName,MonitorStatus,TriggerStatus,TriggerMinimum, TriggerMaximum, ToNurseSupervisor,ToPCP,CurrentProviderID,VitalID,VitalShortName,ToClient))
                      
          
        Next
      
        Log("Client Vitals Settings List")
      
        Return True
      
    Catch
  
        ProgressDialogHide
        Log("SaveReult " & LastException.Message)
        modFun.ShowError("clsGetClientVitalSettings_SaveReult " & LastException.Message)
        Return False
    End Try
End Sub

As you can see - nothing special, sub receives a List created from a JSON that I downloaded from the server.

My app runs a database sync on every start - sends a few post requests to the website and receives JSON.


What it could be?

The app runs on Android SDK: 33 (13). The db file is in rp.GetSafeDirDefaultExternal("") so it doesn't require a permission.
 
Last edited:

Alex_197

Well-Known Member
Licensed User
Longtime User
This could mean that the SQLite database file is in a folder that can't be written to.
Android 13 is hiding the GetSafeDirDefaultExternal folder.
https://www.b4x.com/android/forum/threads/getsafedirdefaultexternal-in-android-13.149526/
This could mean that the SQLite database file is in a folder that can't be written to.
Android 13 is hiding the GetSafeDirDefaultExternal folder.
https://www.b4x.com/android/forum/threads/getsafedirdefaultexternal-in-android-13.149526/
Before this insert there are 10 other inserts into different tables in sync sub. So folder is not a case. Sorry, I didn't mention it in my post.
Could it be that the database was locked for some reason?
 
Upvote 0
Top