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.
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.
Comments