1

The build is success but when it comes to this method, it throws exception. This happened when I updated new packages at NuGet Packages.

public static string checkToken()
        {
            string token1 = "";
            try
            {
                SQLiteConnection db = DependencyService.Get<SQLiteInterface>().GetConnection();
                db.CreateTable<Token>();
            Token t = db.Table<Token>().FirstOrDefault();
            if (t != null)
            {
                DateTime dt = t.timeCreated;
                DateTime tmp = DateTime.Now;

                double diff = (tmp - dt).TotalMinutes;
                if (diff > 60.0 || App.IsUserLoggedIn == false)
                {
                    token1 = "expired";
                    db.Delete(t);
                }
                else
                {
                    token1 = t.token;
                }
            }
        }
        catch (Exception e)
        {
            e.ToString();
        }
        return token1;
    }

Here is the image.

enter image description here

UPDATED:

This packages from .Droid
enter image description here

This package from Portable
enter image description here

9
  • Can you add a list of the SQLite nuget packages you are using? Commented Jan 10, 2020 at 8:00
  • @Janwilx72 from .Droid or Portable? Commented Jan 10, 2020 at 8:01
  • Depends where you're using it. Some of the older SQLite packages gives lots of errors. I essentially removed all packages referring to sqlite in all projects and then used sqlite-net-pcl in the shared project. That means you also don't ave to interface out to create your SQLite db. It works in the shared project Commented Jan 10, 2020 at 8:03
  • @Janwilx72 I already updated the question. Commented Jan 10, 2020 at 8:07
  • What version of xamarin forms are you running? Commented Jan 10, 2020 at 8:28

2 Answers 2

1

It's annoying, but there's a very good chance you're going to have to delete all of those packages and reinstall them. Try to remove them and add the following packages

SQLitePCLRaw.bundle_green Version 1.1.2 in your native projects (Not in PCL)

SQLitePCLRaw.core Version 1.1.2 in your native projects (Not in PCL)

SQLitePCLRaw.lib.e_sqlite3.android Version 1.1.2

SQLitePCLRaw.provider.e_sqlite3.android Version 1.1.2

SQLitePCLRaw.provider.sqlite3.ios_unified Version 1.1.2

and then when you create the database, initialise it using the following code as the path:

string path = System.IO.Path.Combine(System.Environment
            .GetFolderPath(System.Environment.SpecialFolder.Personal), "localstore.db");

OR

If that doesn't work, remove all of them and only add the following one all of your projects

https://www.nuget.org/packages/sqlite-net-pcl/

I hope this helps

Sign up to request clarification or add additional context in comments.

Comments

1

As Janwilx72 said that you need to install sqlite-net-pcl package by Nuget for Pcl and Platforms. Don't need the package that you provided.

enter image description here

Then you can use SQLiteConnection.CreateTable() and have no issue.

I do one sample for Android at github, that you can take a look:

https://github.com/CherryBu/sqliteapp

If you want to do this in ios or other platform, you can take a look this article:

https://dzone.com/articles/register-and-login-using-sqlite-in-xamarinforms

https://learn.microsoft.com/en-us/archive/msdn-magazine/2016/july/xamarin-working-with-local-databases-in-xamarin-forms-using-sqlite

1 Comment

@Ticherhaz, if my reply help you, please remember to mark my reply as answer, thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.