我已将我的.net 2.0项目迁移到.net 4.0. 有了这个,我不得不将system.data.sqlite库升级到可用的最新版本1.0.81。
现在,当我试图查询大表使用select * from table,我得到The database disk image is malformed的错误。这只发生在有大量记录的表上,小表返回记录。
请注意,如果我返回.net 2.0并且system.data.sqlite 1.0.66相同的 DB 文件完美运行。
有任何想法吗?
除了 IIS 上的“无法打开数据库文件”之外,我似乎无法从 SQLite 中获得任何信息。我确信 SQLite 的错误消息和 Oracle 的错误消息一样粗暴。
Full control以下用户授予对 App_Data 和数据库文件的访问权限:IIS_IUSRS、IUSRS、DefaultAppPool和Everyone。我查看过:
SQLite问题“无法打开数据库文件”(该问题自动消失为用户)和许多其他类似的问题,其中大多数是通过更改权限、更改为可写目录(App_Data应该是可写的,不是吗?)或者将相对路径更改为绝对路径(应该|DataDirectory|解析为)。
<connectionStrings>
<add name="sqlite" connectionString="Data Source=|DataDirectory|\datatables.sqlite;Version=3;" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>Unable to open the database file</ExceptionMessage>
<ExceptionType>System.Data.SQLite.SQLiteException</ExceptionType>
<StackTrace>
at System.Data.SQLite.SQLite3.Open(String strFilename, SQLiteConnectionFlags connectionFlags, SQLiteOpenFlagsEnum openFlags, Int32 maxPoolSize, Boolean usePool) at System.Data.SQLite.SQLiteConnection.Open() at AjaxSource.Models.Database.query(String sql, Dictionary`2 parameters) in D:\Tools\Dropbox\Projects\myprojects\AjaxSource\AjaxSource\Models\Database.cs:line …Run Code Online (Sandbox Code Playgroud) 我正在制作一个自定义SQLite包装器.这意味着允许与数据库的预先连接.但是,我在调用此函数两次时收到异常.
public Boolean DatabaseConnected(string databasePath)
{
bool exists = false;
if (ConnectionOpen())
{
this.Command.CommandText = string.Format(DATABASE_QUERY);
using (reader = this.Command.ExecuteReader())
{
while (reader.Read())
{
if (string.Compare(reader[FILE_NAME_COL_HEADER].ToString(), databasePath, true) == 0)
{
exists = true;
break;
}
}
reader.Close();
}
}
return exists;
}
Run Code Online (Sandbox Code Playgroud)
我在执行命令或尝试打开数据库之前使用上面的函数来检查数据库当前是否已打开.第一次执行该函数时,它执行没有问题.之后reader = this.Command.ExecuteReader()抛出异常
Object reference not set to an instance of an object.
StackTrace:
at System.Data.SQLite.SQLiteStatement.Dispose()
at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)
at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SQLite.SQLiteCommand.ExecuteReader()
at …Run Code Online (Sandbox Code Playgroud) 我正在使用数组来保存SQLite查询的结果,此时我正在使用二维表来执行此操作.
我遇到的问题是我必须在使用数组之前手动指定其中一个索引的大小,但感觉就像浪费一样,因为我不知道将返回多少行.我确实使用了一个属性,它允许我检索在数组初始化中使用的存在的列数.
例:
using (SQLiteDataReader dr = cmd.ExecuteReader())
{
results = new object[10,dr.FieldCount];
while (dr.Read())
{
jIterator++;
for (int i = 0; i < dr.FieldCount; i++)
{
results[jIterator, i] = dr.GetValue(i);
}
}
}
//I know there are a few count bugs
Run Code Online (Sandbox Code Playgroud)
存储示例:

我只是将数据添加到数组中,只要while循环返回true,在这个实例中我将第一个索引设置为10,因为我已经知道数据库中有多少元素,10个就足够了.
我将如何更改阵列,以便它的大小可以是动态的,这是否可能基于我获取数据库结果的方式?
我写了一个小的C#/ .Net应用程序,它能够读取Firefox的cookies.sqlite文件.自从我升级到Firefox 4后,我的应用程序无法打开数据库文件:
执行"connection.Open();"行 (在下面的代码示例中)会有一个execption说:
"文件已打开,不是数据库文件.文件已加密或不是数据库"
这是我的程序代码:
class Program
{
static void Main()
{
const string PATH_TO_DATABASE = @"C:\Users\Boris\Desktop\TEMP\cookies.sqlite";
const string CONNECTION_STRING = @"Data Source=" + PATH_TO_DATABASE;
if (!File.Exists(PATH_TO_DATABASE)) return;
using (SQLiteConnection connection = new SQLiteConnection(CONNECTION_STRING))
{
connection.Open();
using (SQLiteCommand command = new SQLiteCommand("SELECT id, name, host, path FROM moz_cookies", connection))
{
using (SQLiteDataReader read = command.ExecuteReader())
{
while (read.Read())
{
string id = read[0].ToString();
string name = read[1].ToString();
string host = read[2].ToString();
string path = read[3].ToString();
Console.WriteLine("ID: " + …Run Code Online (Sandbox Code Playgroud) 使用SQLite运行Nh 3.2会引发以下异常:
---> NHibernate.HibernateException:无法从NHibernate.Driver.SQLite20Driver,NHibernate,Version = 3.2.0.4000,Culture = neutral,PublicKeyToken = aa95f207798dfdb4创建驱动程序.---> System.Reflection.TargetInvocationException:调用目标抛出了异常.---> System.ArgumentException:无法找到请求的.Net Framework数据提供程序.它可能没有安装.
我使用最新的(net 4兼容)版本的SQlite:版本1.0.74.0.我在配置中添加了以下内容:
.Database(SQLiteConfiguration.Standard.InMemory().Raw("hbm2ddl.keywords", "none").ShowSql())
Run Code Online (Sandbox Code Playgroud)
我,也在配置文件中添加:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
Run Code Online (Sandbox Code Playgroud)
奇怪的是,它首先起作用了.现在我得到了上述错误.
我的应用程序使用存储在通过网络提供的文件中的数据库。到目前为止,我一直在使用MS-Access文件 (.accdb),但我正在尝试迁移到SQLite Version 3 (.db3)。
我将 SQLite NuGet 包添加到我的项目中,并使用SQLiteStudio创建了一个 SQLite 数据库。我重构了我的数据库对象以使用System.Data.SQLite.SQLiteConnection而不是System.Data.OleDb.OleDbConnection它运行良好。
但是,我以前的accdb数据库受密码保护,我不知道如何在我当前的 SQLite 数据库上应用密码。
谁能教我怎么做?提前致谢!
我无法概述与 .Net Core 和/或 Standard 一起使用的不同 SQLite 库。看来主要有两个:
MS 库完全独立于 sqlite.org 的库吗?如果是的话,建议使用哪一种?我更喜欢简单性......如果使用 sqlite.org,我似乎只需要两个 dll。
sqlite system.data.sqlite .net-core .net-standard .net-standard-2.0
我正在使用此代码在sqlite表中搜索数字
String insSQL2 = "select * from Produtos where nome =" + txtBuscaNome.Text;
Run Code Online (Sandbox Code Playgroud)
但当我尝试使用它来搜索名称时,我收到一个错误.为什么?
我得到的错误是
System.Data.SQLite.SQLiteException未处理
SQL逻辑错误或缺少数据库
没有这样的专栏:"我输入的文字"
sqlite ×7
c# ×4
.net ×3
.net-core ×1
asp.net-mvc ×1
firefox ×1
iis-7.5 ×1
nhibernate ×1
vb.net ×1