简体   繁体   中英

c# Create new SQLite file using praeclarum/sqlite-net package (SQLite-net PCL)

I am have been searching for the best ORM for SQLite for my project and I have found praeclarum/sqlite-net package

The problem I don't know how I might use this library to create an SQLite file if it does not exists in a directory. There is no documentation about this and I want to create the file in the user's My Documents folder. Here is my code so far.

private string databasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "AttorneySpace\\database.db");
private SQLiteConnection db;

public SQLiteDb()
{
    if (!Directory.Exists(databasePath))
    {
        Directory.CreateDirectory(databasePath);
    }
    db = new SQLiteConnection(databasePath);
    db.CreateTable<Stock>();
    db.CreateTable<Valuation>();
}

For this I get the exception;

An exception of type 'SQLite.SQLiteException' occurred in SQLite-net.dll but was not handled in user code
Could not open database file: ...AttorneySpace\database.db (CannotOpen)

我设法用System.Data.SQLite.SQLiteConnection创建了文件,尽管它不是我正在使用的库的一部分。

System.Data.SQLite.SQLiteConnection.CreateFile(databasePath);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM