How do I reference the Sqlite db file in the App_Data folder for my ASP.NET Web Application?

别来无恙 提交于 2019-12-03 12:34:35

问题


I'm currently storing my sqlite db file in the App_Data folder as per ASP.NET best pattern and practices.

Currently I'm using the following in the webconfig:

  <connectionStrings>
    <add name="sqlite"  
         connectionString="Data Source=|DataDirectory|MyDB; Version=3;" />
  </connectionStrings>

and the following in code:

       public SqliteDAO(string path)
        {
            Connection = new System.Data.SQLite.SQLiteConnection(path );
        }

//...

//where path = |DataDirectory|MyDB

It causes sqlite to make a NEW database (with no tables in it), and thus none of my data access calls work, since they aren't finding the table names. How do I reference the sqlite db file in the App_Data folder from my WebApplication code??

Thanks!


回答1:


Use Server.MapPath to your db file. So it would be something like

Server.MapPath(@"~\App_Data\Your.db");


来源:https://stackoverflow.com/questions/1421247/how-do-i-reference-the-sqlite-db-file-in-the-app-data-folder-for-my-asp-net-web

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