Sqlite connection string in web.config

2019-07-21 03:17发布

问题:

I have published my web project to local iis but framework can't find the "db" file. In debugging there is no problem, i can connect but in localhost i can't. Here is my connection string:

<connectionStrings>
    <add name="PROD" connectionString="data source=app.db;" providerName="System.Data.SQLite"/>
  </connectionStrings>

I tried everything "../app.db" "direct_path" "~/app.db"

What might the problem?


It can find the database in D:\ drive or other than inetpub drive. I didn't understand if it's a permission problem or not. How can i find the exact solution for that?

回答1:

Well i got the physical path with System.AppDomain.CurrentDomain.BaseDirectory and then find the path of sqlite file. It worked!



回答2:

this is most likely a permissions issue. this works while debugging because the website is running under your credentials and you have full control. when deployed it's running under IIS_USRS which is highly restrictive and, most likely, doesn't have write permissions to the file by default.

provide the IIS_USRS account with read/write permissions to the directory/file and this should work.