I developed an applicaiton that works fine <= Windows 7. It uses SQLlite database with VB and C#. However on Windows 8 (Never had this specific problem on other windows os) there is an issue when trying to write to database
System.Data.SQLite.SQLiteException: Attempt to write a read-only database
I created database file on windows 8 pc like:
Try
If (Not File.Exists(System.Environment.CurrentDirectory & "\MY_DB.db")) Then
Dim conn = New SQLite.SQLiteConnection("Version=3;New=True;Compress=False;Read Only=False;Data Source=" & System.Environment.CurrentDirectory & "\MY_DB.db")
conn.Open()
'...DO STUFF
conn.Close()
conn.Dispose()
conn = Nothing
End If
Catch ex As Exception
'Throw ex
Return False
End Try
But didn't work.
So basically I have tried:
Read Only=False
when creating db file but didn't work.What can I do to make databse writable ?
I don't know what is the current directory at the instant of your call, but I would be sure to put my database in a folder where every user have read/write permission by design.
Why don't use the folders represented by the Environment.SpecialFolder enum?
You could change your code to something like this
Try
Dim appFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
appFolder = Path.Combine(appFolder, "MyAppDatabaseFolder")
If Not Directory.Exists(appFolder) Then
Directory.CreateDirectory(appFolder)
End If
Dim myDB = Path.Combine(appFolder, "MY_DB.db")
If (Not File.Exists(myDB)) Then
.....
End If
Catch ex As Exception
'Throw ex
Return False
End Try
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With