Unable to open database (sqlite) in asp.net mvc3 app using spring.net

别说谁变了你拦得住时间么 提交于 2019-12-04 07:15:33

I did a quick test with SQLite, Spring.Net and it fails with the same error, however when I used slashes instead of backslashes in the connection string it magically starts to work.

<db:provider id="employeesDbProvider" 
    provider="SQLite-1.0.72"
    connectionString="Data Source=c:/temp/Database/Sample.db3;Version=3;">
</db:provider>

Edit: I tested a bit further to find out where the file is stored if I use the dot prefix e.g. ./Employees.db3. In IISExpress it is stored in C:\Program Files (x86)\IIS Express most likely not what you did expect.

In IIS7 it simply fails with the Unable to open the database file error, ihmo because it tries to write to the Temporary ASP.NET Files folder.

The safest bet is to use

<db:provider id="employeesDbProvider" 
    provider="SQLite-1.0.72"
    connectionString="Data Source=|DataDirectory|Sample.db3;Version=3;">
</db:provider>

Wich is the App_Data folder of your MVC application.

I used SQLite 1.0.80.0 for my tests. Keep in mind that SQLite does not create the directory and needs ACL write rights.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!