我如何引用App_Data文件夹SQLite的数据库文件为我的ASP.NET Web应用程序? [英] How do I reference the Sqlite db file in the App_Data folder for my ASP.NET Web Application?

查看:121
本文介绍了我如何引用App_Data文件夹SQLite的数据库文件为我的ASP.NET Web应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前储存我的SQLite数据库文件中的App_Data文件夹按照ASP.NET的最佳模式和做法。

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

目前我使用的webconfig以下内容:

Currently I'm using the following in the webconfig:

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

在code以下内容:

and the following in code:

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

//...

//where path = |DataDirectory|MyDB

这导致sqlite的做一个新的数据库(其中不带表),因此没有我的数据访问的工作,因为他们没有找到表名。如何从我的WebApplication code ??

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??

谢谢!

推荐答案

使用要使用Server.Mappath你的数据库文件。因此,它会像

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

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

这篇关于我如何引用App_Data文件夹SQLite的数据库文件为我的ASP.NET Web应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆