2015-10-26 17 views
0

我想为我的ASP.Net网站使用SQLite。 该代码在Windows应用程序中正常工作,但不在WebAPP中。我想我必须更改一些文件权限才能让网站设置数据库。但是如何?如何配置权限:用于ASP.Net网站的SQLite?

我总是在open()声明中得到一个错误。说cannot open file

继代码,这是在WindowsAPP做工精细:

Dim connDB as SQLiteConnection = New SQLiteConnection("PlayerDB.sqlite") 
Dim conn = New SQLiteConnection("Data Source=PlayerDB.sqlite;Version=3") 
conn.open() ---> ERROR 
... 

我希望有人能帮助我快速。

谢谢。

回答

0

有两个原因让你可以得到这个错误,所以你必须确保在运行你的代码之前,这两个都需要照顾。

  • You need to specify the absolute path to the database in your connection string and not a relative path that you are currently using in your code因为SQLite数据库只是一个文件。为此,您需要在ASP.Net应用程序中为sqlite数据库创建一个特殊文件夹。假设您已经在根文件夹下创建了一个名为sqlite的文件夹。那么你的代码应该如下。 Server.MapPath是ASP.Net框架中的一种实用方法,可将根相对路径转换为类似于c:\abc\wwq\myfile.db的绝对路径。

    Dim connDB as SQLiteConnection = New SQLiteConnection(string.Format("Data 
         Source={0};Version=3;",Server.MapPath("~/sqlite/PlayerDB.sqlite"))); 
    
    conn.open() ---> NO ERROR should happen now 
    
  • You should also make sure that the ASP.Net application identity is allowed read/write access to the sqlite的folder created in above step你的web应用程序的根目录下,因为数据将被读取以及写入到该文件夹​​下的数据库文件。

    sqlite文件夹只需点击右键,选择属性然后安全选项卡,如下面的屏幕截图。在大多数本地主机的情况下,ASP.Net标识是IIS_IUSRS,在下面突出显示。确保此用户完全控制sqlite文件夹。

enter image description here