gpt4 book ai didi

c# - System.Data.SQLite.SQLiteException 尝试在 Windows 8 上写入只读数据库

转载 作者:IT王子 更新时间:2023-10-29 06:28:42 24 4
gpt4 key购买 nike

我开发了一个运行良好 <= Windows 7 的应用程序。它使用带有 VB 和 C# 的 SQLlite 数据库。但是在 Windows 8 上(在其他 Windows 操作系统上从未遇到过这个特定问题)尝试写入数据库时​​出现问题

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

我在 Windows 8 电脑上创建了数据库文件,如:

 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

但是没用。

所以基本上我已经尝试过:

  1. 在创建 db 文件时添加了 Read Only=False 但没有用。
  2. 数据库所在的文件夹必须具有写入权限,以及实际的数据库文件。这样做了,但没有用(在 Windows 7 上看起来像 enter image description here )。

我该怎么做才能使数据库可写?

最佳答案

我不知道你打电话时的当前目录是什么,但我肯定会把我的数据库放在一个文件夹中,每个用户在设计上都具有读/写权限。

为什么不使用 Environment.SpecialFolder 代表的文件夹?枚举?

你可以把你的代码改成这样

 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

关于c# - System.Data.SQLite.SQLiteException 尝试在 Windows 8 上写入只读数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20764269/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com