System.Data.SQLite。SQLiteException试图在Windows 8上写入只读数据库

时间:2023-01-17 23:01:32

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

我开发了一个适用于Windows 7的应用程序。它使用VB和c#的SQLlite数据库。但是在Windows 8上(在其他Windows操作系统上从未有过这个问题),在尝试写入数据库时存在一个问题。

System.Data.SQLite.SQLiteException: Attempt to write a read-only database

I created database file on windows 8 pc like:

我在windows 8 pc上创建了数据库文件,比如:

 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:

基本上我试过

  1. Added Read Only=False when creating db file but didn't work.
  2. 在创建db文件时添加只读=False,但没有工作。
  3. The folder the database resides in must have write permissions, as well as the actual database file. So did it, didn't work (on windows 7 would look like System.Data.SQLite。SQLiteException试图在Windows 8上写入只读数据库).
  4. 数据库所在的文件夹必须具有写权限,以及实际的数据库文件。这样做了,没有成功(windows 7看起来就像这样)。

What can I do to make databse writable ?

我可以做什么来让databse可写?

1 个解决方案

#1


5  

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?

为什么不使用环境表示的文件夹呢?SpecialFolder枚举?

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

#1


5  

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?

为什么不使用环境表示的文件夹呢?SpecialFolder枚举?

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