我使用Visual Studio 2015 SP2.我尝试使用sqlite创建Windows Universal应用程序.我为Unversal Windows平台和SQLite.Net-PCl添加了SQLite.这是我简单的代码
var conn = new SQLiteConnection(
new SQLitePlatformWinRT(),
Path.Combine(ApplicationData.Current.LocalFolder.Path, "Storage.sqlite"));
Run Code Online (Sandbox Code Playgroud)
它适用于桌面.但它不适用于移动设备(在设备和模拟器中).我得到这个异常System.DllNotFoundException:
HResult=-2146233052
Message=Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Source=SQLite.Net.Platform.WinRT
TypeName=""
StackTrace:
at SQLite.Net.Platform.WinRT.SQLite3.SetDirectory(UInt32 directoryType, String directoryPath)
at SQLite.Net.Platform.WinRT.SQLiteApiWinRT..ctor()
at SQLite.Net.Platform.WinRT.SQLitePlatformWinRT..ctor()
at AppDbTest.MainPage.DbConnection()
at AppDbTest.MainPage..ctor()
at AppDbTest.AppDbTest_XamlTypeInfo.XamlTypeInfoProvider.Activate_0_MainPage()
at AppDbTest.AppDbTest_XamlTypeInfo.XamlUserType.ActivateInstance()
Run Code Online (Sandbox Code Playgroud)
我尝试这种方法.我重新安装SQLite for Unversal Windows Platforms扩展和SQLite.Net-PCl.我创建了明确的项目.但它对我不起作用.
sqlite windows-phone sqlite-net win-universal-app visual-studio-2015
在我们的Xamarin Android项目中,我们试图从sqlite-net切换到官方的sqlite-net-pcl包.
但是在创建新的SQLiteConnection后进行此切换后,我遇到以下异常:
'SQLite.SQLiteConnection'的类型初始值设定项引发了异常.---> System.DllNotFoundException:e_sqlite3
完全例外:
Xamarin引起的:android.runtime.JavaProxyThrowable:System.TypeInitializationException:'SQLite.SQLiteConnection'的类型初始值设定项引发异常.---> System.DllNotFoundException:e_sqlite3 at(wrapper managed-to-native)SQLitePCL.SQLite3Provider_e_sqlite3 + NativeMethods:siteite3_libversion_number()at SQLitePCL.SQLite3Provider_e_sqlite3.SQLitePCL.ISQLite3Provider.sqlite3_libversion_number()[0x00000] in:0 at SQLitePCL.raw. SQL4中的Setitevider(SQLitePCL.ISQLite3Provider imp)[0x00000]:SQLitePCL.Batteries_V2.Init()[0x0000d]中的<1125db7e18f0475797b2764ec6653cf1>:0中的/,/ Users/fak中的SQLite.SQLiteConnection..cctor()[0x00000]中的0 /Dropbox/Projects/sqlite-net/src/SQLite.cs:171 ---内部异常堆栈跟踪结束---在mono.android.view.View_OnClickListenerImplementor上的mono.android.view.View_OnClickListenerImplementor.n_onClick(本机方法) .onClick(View_OnClickListenerImplementor.java:30)在android.view.View.performClick(View.java:4780)的android.view.View $ PerformClick.run(View.java:19866)android.os.Handler.handleCallback( Handler.java:739)在android.os.Handler.dispatchMessage(Handler.jav a:95)在android.app.Looper.loop(Looper.java:135)的android.app.ActivityThread.main(ActivityThread.java:5254)java.lang.reflect.Method.invoke(Native Method)at java位于com.android.internal.os.ZygoteInit.main的com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)中的.lang.reflect.Method.invoke(Method.java:372)(ZygoteInit)的.java:698)
在日志中我可以看到以下信息:
12-01 10:43:05.356 D/Mono(11194):DllImport试图加载:'e_sqlite3'.12-01 10:43:05.358 D/Mono(11194):DllImport错误加载库'/storage/emulated/0/Android/data/com.psonar.android/files/.覆盖/libe_sqlite3' :"dlopen的失败:库"/data/app/com.psonar.android-1/lib/x86//storage/emulated/0/Android/data/com.psonar.android/files/ 覆盖/libe_sqlite3"找不到".12-01 10:43:05.360 D/Mono(11194):DllImport错误加载库'/storage/emulated/0/Android/data/com.psonar.android/files/.override /libe_sqlite3.so':'dlopen failed:library"/data/app/com.psonar.android-1/lib/x86//storage/emulated/0/Android/data/com.psonar.android/files/.覆盖 /libe_sqlite3.so"未找到".12-01 10:43:05.360 D/Mono(11194):DllImport错误加载库'/ system/lib/libe_sqlite3':'dlopen failed:library"/data/app/com.psonar.android-1/lib/x86 // system/lib/libe_sqlite3"找不到".12-01 10:43:05.360 D/Mono(11194):DllImport错误加载库'/system/lib/libe_sqlite3.so':'dlopen failed:library"/data/app/com.psonar.android-1/lib /x86//system/lib/libe_sqlite3.so"未找到".12-01 10:43:05.360 D/Mono(11194):DllImport错误加载库'libe_sqlite3':'dlopen failed:library"/data/app/com.psonar.android-1/lib/x86/libe_sqlite3"未找到".12-01 10:43:05.361 D/Mono(11194):DllImport错误加载库'libe_sqlite3.so':'dlopen failed:library"/data/app/com.psonar.android-1/lib/x86/libe_sqlite3.所以"没找到".12-01 10:43:05.361 D/Mono(11194):DllImport错误加载库'e_sqlite3':'dlopen failed:library"/data/app/com.psonar.android-1/lib/x86/e_sqlite3"未找到".12-01 10:43:05.362 D/Mono(11194):DllImport错误加载库'/storage/emulated/0/Android/data/com.psonar.android/files/.覆盖/libe_sqlite3' :"dlopen的失败:库"/data/app/com.psonar.android-1/lib/x86//storage/emulated/0/Android/data/com.psonar.android/files/ 覆盖/libe_sqlite3"找不到".12-01 10:43:05.364 D/Mono(11194):DllImport错误加载库'/storage/emulated/0/Android/data/com.psonar.android/files/.override /libe_sqlite3.so':'dlopen failed:library"/data/app/com.psonar.android-1/lib/x86//storage/emulated/0/Android/data/com.psonar.android/files/.覆盖 …
android xamarin.android xamarin sqlite-net sqlite-net-extensions
有人可以帮助我理解为什么这很好用吗...
Dim cs = "Data Source=C:\folder\Livros.sdb;Version=3;"
Dim cn = New System.Data.SQLite.SQLiteConnection(cs)
cn.Open() ' no exception
Run Code Online (Sandbox Code Playgroud)
...虽然打开连接时会中断(它是完全相同的文件)...
Dim cs = "Data Source=\\NetworkServer\folder\Livros.sdb;Version=3;"
Dim cn = New System.Data.SQLite.SQLiteConnection(cs)
cn.Open() ' exception: {"unable to open database file"}
Run Code Online (Sandbox Code Playgroud)
...并修复它,因为我需要将数据库文件放置在网络位置,以便无论运行应用程序的计算机如何,我都可以访问它?
非常感谢!
我有一个这样的SQL语句:
Global.db.Query<Cards>("select * from Cards where card_name like ?", nameTextBox.Text);
Run Code Online (Sandbox Code Playgroud)
但是我想用参数值向这样的双方添加%.
Global.db.Query<Cards>("select * from Cards where card_name like %?%", nameTextBox.Text);
Run Code Online (Sandbox Code Playgroud)
但是当我尝试执行此操作时,我正在抛出错误.当我使用像这样的语句时,为什么它崩溃的任何想法?我在我的sqlite管理程序中使用相同的数据库运行相同的查询,结果就像他们应该的那样.
我开始重建我的应用程序到MvvmCross,但我遇到了一个小障碍.似乎SQLite的社区插件不支持异步连接和查询.WinRT需要数据访问和其他长时间运行的操作异步执行,所以这似乎是一个问题(虽然我认为可以肯定地说,正常的操作不需要那么长时间才能解决这个问题).我只是想问一下,如果异步支持在某种程度上可以添加,并且如果在将来的版本中以某种方式添加此功能.
非常感谢你们!
再次是我,那个使用SQLite-net的人。当我在表的主键上没有自动增量功能时,我的代码可以正常工作。我想自动递增键,所以我像这样重建了表:
using SQLite;
namespace VehicleTracks.Models
{
public class vehicles
{
[PrimaryKey, AutoIncrement]
public int ID { get; set; }
public string VehID { get; set; }
public string VehYear { get; set; }
public string VehMake { get; set; }
public string VehModel { get; set; }
public string VehColor { get; set; }
public string EngineID { get; set; }
public System.DateTime PurchaseDate { get; set; }
public string SellerName { get; set; }
public string SellerStreet { get; …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的Xamarin.iOS项目中将Sqlite ThreadMode设置为Serialized.使用经典的Sqlite,可以在连接类上找到此方法:
SqliteConnection.SetConfig(SQLiteConfig.Serialized);
但是我使用sqlite-net(+ async)并且无法找到设置此配置属性的方法.
有什么建议?
我对此进行了研究,我所能找到的只是一个打开 .Trace = true 的建议,如下所示:
db1 = DependencyService.Get<ISQLite>().GetConnection();
db1.Trace = true;
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
db2.Trace = true;
var categories = db2.Query<Category>("SELECT * FROM Category ORDER BY Name").ToList();
Debug.WriteLine("xxxx");
Run Code Online (Sandbox Code Playgroud)
好吧,我这样做了,然后重新启动了应用程序。当我查看应用程序输出时,我只看到有关已启动线程和 xxxx 的信息,但没有看到任何 SQL 跟踪信息。
谁能给我这方面的建议。谢谢
我创建了一个 .net 标准类库服务,用于在我的新 Maui 应用程序中访问 sqlite 数据库。我的问题是在哪里调用初始化代码。我添加了 DI 注册,其中MauiProgram.cs将 my 注册DbService为接口的实现IDbService:
builder
.Services
.AddSingleton<IDbService>(serviceProvider =>
ActivatorUtilities.CreateInstance<DbService>(serviceProvider, databasePath))
.AddSingleton<MainViewModel>()
.AddSingleton<MainPage>();
Run Code Online (Sandbox Code Playgroud)
初始化数据库的代码(创建表、加载测试数据)我目前已放入主页视图模型的构造函数中,该视图模型注册为单例,因此初始化只会发生一次。但显然在构造函数中调用异步初始化代码是错误的。正确的位置在哪里?
Task.Run(async () =>
{
await _dbService.Initialise();
if (!(await _dbService.GetExperiences(1, 0)).Any())
await _dbService.LoadTestData();
await GetData();
}).GetAwaiter().GetResult();
Run Code Online (Sandbox Code Playgroud) 我正在构建一个使用 SQLite 作为存储数据库的 Windows 8 C#/XAML 应用程序,我正在尝试使用 SQLite-net 语法创建多个表。
从我到目前为止的研究来看,一个表是基于一个类创建的。首先,我通过以下方式创建了一个“帐户”类:
public class Account
{
[PrimaryKey, AutoIncrement]
public int ID { get; set; }
public string Name { get; set; }
public string Type { get; set;}
}
Run Code Online (Sandbox Code Playgroud)
然后创建一个表并通过以下方式在代码中输入初始数据:
private static readonly string _dbPath =
Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "data.sqlite");
using (var db = new SQLite.SQLiteConnection(_dbPath))
{
db.CreateTable<Account>();
db.RunInTransaction(() =>
db.Insert(new Account()
{
Name = "MyCheckingAccount",
Type = "Checking",
})
);
}
Run Code Online (Sandbox Code Playgroud)
我想创建多个帐户表,但db.CreateTable<Account>()语法只是创建一个表,数据插入到列中,db.Insert().我看不到在哪里输入表本身的名称。
我如何创建多个表,即一个名为“BusinessAccounts”和另一个基于 Account 类的“PersonalAccounts”?
有没有办法用 SQLite-net 做到这一点?或者我是否需要以某种方式明确写出 SQLite …