Can I add the SQLite.NET component to my cross-platform Xamarin.Forms project?
I don't see any option to add components, I can only do that for the native Android/iOS project.
Edit: Which doesn't seem to be working:
System.Exception: Something went wrong in the build configuration. This is the bait assembly, which is for referencing by portable libraries, and should never end up part of the app. Reference the appropriate platform assembly instead.
@SpaceMonkey Have you been able to resolve the exception? I'm getting the same thing. From what I understand it's because the platform specific sqlite implementation isn't being loaded, but I haven't been able to figure out how to fix that.
public SQLiteConnection Connect()
{
var fileName = "my_file.db3";
var documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var path = Path.Combine(documentsPath, fileName);
var connection = new SQLiteConnection(path);
return connection;
}
I receive an exception when executing:
var connection = new SQLiteConnection(path);
Something went wrong in the build configuration. This is the bait
assembly, which is for referencing by portable libraries, and should
never end up part of the app.
NOTE:
SQLitePCL.raw_basic is on 0.7.1
I get errors whenever I attempt to upgrade the version to 0.8.1
Again, this all worked before I installed VS2015 RTM
Any suggestions?
Answers
There is a PCL sqlite library you can use.
https://www.nuget.org/packages/SQLite.Net-PCL/
@ken_tucker actually, I've just found out that the SQLite.NET component suggested by Xamarin does have a PCL package on NuGet. Thanks a lot
@ken_tucker nevermind, the one I posted doesn't work, I will try what you suggested.
I'm an idiot. There is a PCL version:
https://www.nuget.org/packages/sqlite-net-pcl/
Edit: Which doesn't seem to be working:
System.Exception: Something went wrong in the build configuration. This is the bait assembly, which is for referencing by portable libraries, and should never end up part of the app. Reference the appropriate platform assembly instead.
@SpaceMonkey Have you been able to resolve the exception? I'm getting the same thing. From what I understand it's because the platform specific sqlite implementation isn't being loaded, but I haven't been able to figure out how to fix that.
@ScottMacRitchie
I don't even remember why I said what I said in the previous comment. Anyway:
Add SQLite-Net-PCL to the PCL project and the native project too.
In your PCL when you need to initialise a new connection you'll need an ISQLitePlatform implementation. You do that using dependency injection:
So in the PCL you're doing:
and in the native project (Android in my case) you're doing:
Thanks @SpaceMonkey
I receive an SQLite exception when creating a connection.
This worked before I installed VS2015 RTM.
Client (PCL):
Android project:
I receive an exception when executing:
NOTE:
SQLitePCL.raw_basic is on 0.7.1
I get errors whenever I attempt to upgrade the version to 0.8.1
Again, this all worked before I installed VS2015 RTM
Any suggestions?
@ScottNimrod
Are you using this:
https://www.nuget.org/packages/SQLite.Net-PCL/
The way I explained in the previous comment?
@SpaceMonkey
I followed your steps. But I am confused.
I just don't know what to do with the platform object.
var platform = DependencyService.Get().GetSqlite();
It's not apparent to me on how I am to perform any CRUD operation with this platform interface.
Any suggestions?
@ScottNimrod
Creating a connection requires an object implementing ISQLitePlatform. You should pass the object you get using DependecyService
Refer the below link to get working sample about SQLite.NET :
C-Sharp Corner : Interacting With Local Database in Xamarin.Forms
after installation SQLite-net-pcl, I donot see SQLite.net namespace, but only see sqlit namespace
why?
thanks
jeffchen.5589 Did you figure out where SQLite.net is?
For me the fix was to uninstall the package SQLite-net-pcl and install SQLite-Net-PCL. Notice the difference in punctuation.
I did this in PCL and platform projects.