How can i create a database using SQLite on Xamarin forms?

sunboy

I have been using SQLite-net-pcl to add a database to my application but when i try to create the database it throws this exception SQLite.SQLiteException: 'Could not open database file: mydatabase.db3 (Misuse)'.

public class MySQLDatabase
{
    private static SQLiteAsyncConnection db;

    public void MyDatabase()
    {
        if (db != null)
        {
            return;
        }

        string databasepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "mydatbase.db3");
        db = new SQLiteAsyncConnection(databasepath);
        db.CreateTableAsync<MyTable>();
    }

    public void InsertData(int gameid, string preorder,string rating,string standards,string overpriced,string agerating,string gameplay,string recommend,string impact)
    {
        MyTable myNewTable = new MyTable
        {
            GameId = gameid,
            PreOrder = preorder,
            Rating = rating,
            Standards = standards,
            OverPriced = overpriced,
            AgeRating = agerating,
            Gameplay = gameplay,
            Recommend = recommend,
            Impact = impact
        };
        conn.Insert(myNewTable);
    }

    public void CloseConnection()
    {
        conn.Close();
    }
}

I have seen other solutions to this problem using SQLiteConnection.CreateFile() but for some reason, this method doesn't show up for me. I am using the SQLite-net-pcl 1.8.116 version.

lapoPaolacci

this is method I use for create and migrate Sqlite DB in Xamarin.Forms:

var _rootFolder = new LocalRootFolder();
var connection = new SQLiteAsyncConnection(Path.Combine(rootFolder.Path, "my_db.sqlite"));
await connection.CreateTableAsync<My_Table>();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How I can create animation in Xamarin.Forms using MVVM

With Xamarin Forms, how can I create my SQLite connections in shared code?

How can I read a `uuid` from a column in a sqlite3 db using sqlite-net-pcl in Xamarin Forms

Can I create a Whitelist for Safari using OpenUrl in Xamarin.Forms?

How to update an item in database with SQLite in Xamarin forms

How can I create a drawer / slider menu with Xamarin.Forms?

how can I create a rectangular as big as the screen in Xamarin Forms?

How can I connect Xamarin Android app to an existing Sqlite database?

How can I create a new table in my SQLite Database using a param from a Java String variable?

How can I remove a column from my SQLite table with sqlite-net-pcl that comes with Xamarin Forms?

How can I create an in-memory database with sqlite?

How can I create a windows forms project using .NET Core?

How To Create Feature Discovery Using Xamarin Forms

How to store images in sqlite database in Xamarin Forms for cross platforms application?

How To Maintain SQLite Database State in Xamarin Forms Between Deploys/Builds

How can i pass a color to my UI if my property is a string in my database (xamarin.forms)

How can I create a xaml with comments area along with overlay in Xamarin Forms

Can i create a cross platform Xamarin Forms application in F#?

How can I create a database from a file using Java?

How can I create a subset a database using multiple conditions?

Items in database sqlite are not updating (Xamarin.Forms)

Which SQLite database to be downloaded for Xamarin.Forms

SQLite Xamarin Forms Database Table to ListView

Xamarin.forms Backup a SQLite database

Can I create a cross-platform app with Xamarin using a MySQL database?

How can I create an array of forms in angular?

How can I await modal form dismissal using Xamarin.Forms?

How can I add a button inside var content page code-behind using Xamarin.Forms?

Using Xamarin Forms - how can I hook up a button click to a swipe gesture?