【问题标题】:How to add SQLite (SQLite.NET) to my C# project如何将 SQLite (SQLite.NET) 添加到我的 C# 项目中
【发布时间】:2011-02-09 13:19:25
【问题描述】:

我按照文档中的说明进行操作:

场景 1:版本无关(不使用全局程序集缓存)

此方法允许您删除任何新的 System.Data.SQLite.DLL 的版本 进入您的应用程序的文件夹并使用 它无需任何代码修改或 重新编译。添加以下代码 到您的 app.config 文件:

<configuration>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite"/>
      <add name="SQLite Data Provider" invariant="System.Data.SQLite"
           description=".Net Framework Data Provider for SQLite"           type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
    </DbProviderFactories>
  </system.data>
</configuration>

我的 app.config 文件现在如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="DataFeed.DataFeedSettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <userSettings>
        <DataFeed.DataFeedSettings>
            <setting name="eodData" serializeAs="String">
                <value>False</value>
            </setting>
        </DataFeed.DataFeedSettings>
    </userSettings>
    <system.data>
      <DbProviderFactories>
        <remove invariant="System.Data.SQLite"/>
        <add name="SQLite Data Provider" 
             invariant="System.Data.SQLite"
             description=".Net Framework Data Provider for SQLite" 
             type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
      </DbProviderFactories>
    </system.data>
</configuration>

我的项目名为“DataFeed”:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite; //<-- Causes compiler error

namespace DataFeed
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}

我得到的错误是:

.\dev\DataFeed\Program.cs(5,19): 错误 CS0234:类型或命名空间 名称“SQLite”不存在于 命名空间“System.Data”(你是 缺少程序集引用?)

我不喜欢使用 GAC,所以我只是将 System.Data.SQLite.dll 放到了我的 .\dev\DataFeed\ 文件夹中。我认为我需要做的就是将 DLL 添加到文档中提到的项目文件夹中,但我无法使用该库。有关如何实际完成这项工作的任何提示?

【问题讨论】:

    标签: c# sql database visual-studio-2008 sqlite


    【解决方案1】:

    您将 DLL 放入您的 .\Dev\DataFeed 文件夹中 - 您是否将对该 DLL 的引用添加到您的项目中?您收到的错误似乎表明您没有设置对该 DLL 的引用 - 这不会自行发生,如果您想使用外部 DLL 中的内容,您需要手动添加对外部 DLL 的引用。

    【讨论】:

    • @Lirik:有时是一些简单的东西阻碍了你,而你自己却看不到 :-) 去过那里,经历过......
    • 我猜它会发生,尤其是在凌晨 1:00 :)...大脑开始考虑睡觉,而我仍然要求它考虑发育。
    猜你喜欢
    • 2016-12-28
    • 1970-01-01
    • 1970-01-01
    • 2019-12-03
    • 1970-01-01
    • 1970-01-01
    • 2017-05-29
    • 2014-03-07
    相关资源
    最近更新 更多