[英]How to add SQLite (SQLite.NET) to my C# project
I followed the instructions in the documentation: 我按照文档中的说明操作:
Scenario 1: Version Independent (does not use the Global Assembly Cache) 场景1:版本无关(不使用全局程序集缓存)
This method allows you to drop any new version of the System.Data.SQLite.DLL into your application's folder and use it without any code modifications or recompiling. 此方法允许您将任何新版本的System.Data.SQLite.DLL删除到应用程序的文件夹中,并在不进行任何代码修改或重新编译的情况下使用它。 Add the following code to your app.config file: 将以下代码添加到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>
My app.config file now looks like this: 我的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>
My project is called "DataFeed": 我的项目名为“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)
{
}
}
}
The error I get is: 我得到的错误是:
.\\dev\\DataFeed\\Program.cs(5,19): error CS0234: The type or namespace name 'SQLite' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) 。\\ dev \\ DataFeed \\ Program.cs(5,19):错误CS0234:命名空间“System.Data”中不存在类型或命名空间名称“SQLite”(您是否缺少程序集引用?)
I'm prefer not to use the GAC so I simply dropped the System.Data.SQLite.dll
into my .\\dev\\DataFeed\\
folder. 我不想使用GAC,所以我只是将System.Data.SQLite.dll
放入我的.\\dev\\DataFeed\\
文件夹中。 I thought that all I needed to do is add the DLL to the project folder as it was mentioned in the documentation, but I can't use the library. 我认为我需要做的就是将DLL添加到文档中提到的项目文件夹中,但我无法使用该库。 Any hints on how to actually make this work? 关于如何实现这项工作的任何提示?
You dropped the DLL into your .\\Dev\\DataFeed
folder - and did you add a reference to that DLL to your project?? 您将DLL删除到.\\Dev\\DataFeed
文件夹中 - 并且您是否已将该DLL的引用添加到您的项目中? The error you get seems to indicate you don't have a reference set up to that DLL - this won't happen just by itself, you need to manually add a reference to an external DLL if you want to use stuff from it. 你得到的错误似乎表明你没有设置到该DLL的引用 - 这不会单独发生,如果你想使用它的东西,你需要手动添加对外部DLL的引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.