所以我在System.Data.SQLite和使用多个事务时遇到了一个有趣的问题.基本上我有以下代码失败:
using (IDbConnection connection1 = new SQLiteConnection("connectionstring"), connection2 = new SQLiteConnection("connectionstring"))
{
connection1.Open();
connection2.Open();
IDbTransaction transaction1 = connection1.BeginTransaction();
IDbTransaction transaction2 = connection2.BeginTransaction(); // Fails!
using(IDbCommand command = new SQLiteCommand())
{
command.Text = "CREATE TABLE artist(artistid int, artistname text);";
command.CommandType = CommandType.Text;
command.Connection = connection1;
command.ExecuteNonQuery();
}
using (IDbCommand command = new SQLiteCommand())
{
command.Text = "CREATE TABLE track(trackid int, trackname text);";
command.CommandType = CommandType.Text;
command.Connection = connection2;
command.ExecuteNonQuery();
}
transaction1.Commit();
transaction2.Commit();
}
Run Code Online (Sandbox Code Playgroud)
从我所看到的,似乎System.Data.SQLite应该支持嵌套和扩展顺序事务.代码在第7行(声明第二个事务)失败,但有以下异常:
System.Data.SQLite.SQLiteException: The database file is locked
System.Data.SQLite.SQLite3.Step(SQLiteStatement …Run Code Online (Sandbox Code Playgroud) (这是一个重复的问题,已在stackoverflow.com中提出.我已经阅读了答案.我已经尝试了解决方案,但这并没有解决我的问题.我将解释我的问题是什么以及有什么问题我做完了).
这是我的问题:
我的应用程序使用System.Data.SQLite.DLL.我引用它并在我的计算机中正常运行,但它无法在另一台计算机上运行.这是错误消息:
System.IO.FileLoadException:无法加载文件或程序集'System.Data.SQLite,Version = 1.0.88.0,Culture = neutral,PublicKeyToken = db937bc2d44ff139'或其依赖项之一.应用程序无法启动,因为它的并排
配置不正确.有关更多详细信息,请参阅应用程序事件日志或使用命令行sxstrace.exe工具.
(来自HRESULT的异常:0x800736B1)文件名:'System.Data.SQLite,Version = 1.0.88.0,Culture = neutral,PublicKeyToken = db937bc2d44ff139'---> System.Runtime.InteropServices.COMException(0x800736B1):应用程序失败开始,因为它的并排
配置不正确.有关更多详细信息,请参阅应用程序事件日志或使用命令行sxstrace.exe工具.
(来自HRESULT的异常:0x800736B1)SimPB.config.PrepareDatabase(),位于SimPB.Program.Main()的SimPB.config.InitializeProgram()
我的电脑运行Windows 7 32位,Visual Studio 2010.
另一台计算机也运行Windows 7 32位,没有安装Visual Studio.
我尝试过的:
尝试1:确保使用Release + x86构建应用程序,并使用目标框架构建应用程序:.NET Framework 2.0.完成.
尝试2:确保使用正确版本的System.Data.SQLite引用该应用程序,该版本是x86 + .Net Framework 2.0(sqlite-netFx20-binary-Win32-2005-1.0.88.0).完成
尝试3:在App.config上尝试这些代码:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
Run Code Online (Sandbox Code Playgroud)
还有这个
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<runtime>
<NetFx40_LegacySecurityPolicy enabled="true"/>
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)
还有这个
<?xml version="1.0" …Run Code Online (Sandbox Code Playgroud) 我试图使用参数化查询运行批量删除.目前,我有以下代码:
pendingDeletions = new SQLiteCommand(@"DELETE FROM [centres] WHERE [name] = $name", conn);
foreach (string name in selected)
pendingDeletions.Parameters.AddWithValue("$name", name);
pendingDeletions.ExecuteNonQuery();
Run Code Online (Sandbox Code Playgroud)
但是,参数的值似乎每次都被覆盖,我最终只删除了最后一个中心.使用值列表执行参数化查询的正确方法是什么?
如何备份SQLite内存数据库?我在Windows应用程序中创建数据库.我想在关闭应用程序时进行数据库备份.
我将我们产品的数据库从另一个支持Guids的产品移植到SQLite.众所周知,SQLite不支持Guids.我已经从我的数据库(数据库优先)创建了一个实体框架6模型,我需要从C#构建一个查询,将Guid与从代码传递的Guid进行比较.
问题是我找不到任何关于SQLite实体框架提供程序如何处理Guids的文档.网络搜索也找不到对我有用的东西.关于在SQLite中使用Entity Framework的问题.
任何人都可以指向我的文档,或者告诉我如何通过EF6模型在SQLite数据库中使用Guids?
c# sqlite entity-framework system.data.sqlite entity-framework-6
我正在使用SQLite.我可以在我的WPF应用程序中使用实体框架6.1.3没有问题,但是当我将其更新到6.2.0时,我收到以下错误:
Test method DataAccessLayerTests.GenericDataRepositoryTests.CRUD_On_Pipe threw exception:
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'SQLiteConnection'.
at System.Data.SQLite.SQLiteConnection.CheckDisposed()
at System.Data.SQLite.SQLiteConnection.get_State()
at System.Data.Entity.Internal.RepositoryBase.CreateConnection()
at System.Data.Entity.Migrations.History.HistoryRepository.QueryExists(String contextKey)
at System.Data.Entity.Migrations.History.HistoryRepository.Exists(String contextKey)
at System.Data.Entity.Migrations.History.HistoryRepository.GetPendingMigrations(IEnumerable`1 localMigrations)
at System.Data.Entity.Migrations.DbMigrator.GetPendingMigrations()
at Core.DatabaseContext.CreateAndSeedIfNotExists`1.InitializeDatabase(T context) in C:\Users\roadrunner\propulsimcs\Propulsim\Core\DatabaseContext.cs:line 40
at System.Data.Entity.Internal.InternalContext.<>c__DisplayClassf`1.<CreateInitializationAction>b__e()
at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c)
at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
at System.Data.Entity.Internal.InternalContext.Initialize()
at System.Data.Entity.Database.Initialize(Boolean force)
at Core.DatabaseContext..ctor() in C:\Users\roadrunner\propulsimcs\Propulsim\Core\DatabaseContext.cs:line 114
at DataAccessLayer.GenericDataRepository`1.GetAll(Expression`1[] navigationProperties) in C:\Users\roadrunner\propulsimcs\Propulsim\DataAccessLayer\GenericDataRepository.cs:line 16
at DataAccessLayerTests.GenericDataRepositoryTests.CRUD_On_Pipe() in C:\Users\roadrunner\propulsimcs\Propulsim\DataAccessLayerTests\GenericDataRepositoryTests.cs:line 34
Debug Trace:
Native …Run Code Online (Sandbox Code Playgroud) 我最近将我的SQL Server数据库转换为SQLite DB.但是当我尝试使用.Open()它打开我的SQLite时会抛出这个错误:
Data Source cannot be empty. Use :memory: to open an in-memory database
Run Code Online (Sandbox Code Playgroud)
编辑:添加连接字符串:
ConnectionString = @"Data Source=D:\XXX.db;Version=3";
connection = new SQLiteConnection(connectionString);
connection.Open();
Run Code Online (Sandbox Code Playgroud)
为什么我这样做?我将相同的SQL Server数据库转换为SQL CE和mySQL,但我没有得到这些错误.
有了WiX,我想发布一个使用SQLite的C#程序.
SQLite推荐下面的文件结构,所以我使用它:

在Wix中,我创建了x86和x64文件夹,并在每个文件夹中放入了正确的DLL:
<Directory Id='x86' Name='x86'>
<Component Id='x86' Guid='...'>
<CreateFolder />
<File Id='f86' Name='SQLite.Interop.dll' Source='x86\SQLite.Interop.dll' />
</Component>
</Directory>
<Directory Id='x64' Name='x64'>
<Component Id='x64' Guid='...'>
<CreateFolder />
<File Id='f64' Name='SQLite.Interop.dll' Source='x64\SQLite.Interop.dll' />
</Component>
</Directory>
Run Code Online (Sandbox Code Playgroud)
问题: WiX说error LGHT0204 : ICE99: The directory name: x64 is the same as one of the MSI Public Properties and can cause unforeseen side effects.
提示:如果我从WiX脚本中删除这两个目录,然后手动将它们复制到安装程序的位置,那么它可以工作.这听起来很愚蠢,但也许解决方案是在WiX脚本中创建x86_和x64_目录,并在首次执行程序时重命名它们?
我使用System.Data.SQLite.SQLiteFunction在C#中创建了一些自定义SQLite函数.当使用SQLiteDataAdapter执行查询时,它工作得很好,但它不起作用,但是,当使用Linq to SQL时,我会收到错误,指出该函数不存在.
我想底线是,如何让Custom SQLiteFunctions在Linq to SQL中工作?要么让它们加载它们应该的方式,要么通过修改SQLite.Net的源代码使它们成为dll的一部分?
注意:我理解实体框架是首选,这是遗留应用程序,我没有选项来更改它.我尝试手动将函数绑定到DataContext.Connection,没有骰子.
关于尝试修改System.Data.SQLite的背景:我尝试下载源代码,我可以从源代码成功构建,但源代码对我来说有点令人费解.
这样做的目的是尝试将我的自定义函数构建到System.Data.SQLite.dll中,而不是依赖于通过反射自动加载.
System.Data.SQLite和Microsoft.Data.Sqlite有什么区别?
我知道System.Data.SQLite较旧,并且在Microsoft.Data.Sqlite之后获得了.NETStandard支持,但是现在它们都支持.NETStandard 2。
一个相对于另一个的优点是什么?