简体   繁体   English

c#使用praeclarum / sqlite-net包(SQLite-net PCL)创建新的SQLite文件

[英]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 我一直在为我的项目寻找SQLite的最佳ORM,并且发现了praeclarum / sqlite-net包

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. 这个问题我不知道如果目录中不存在该SQLite文件,我将如何使用它来创建它。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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