简体   繁体   English

SQLite ADO.net连接和部署问题

[英]Problems with SQLite ADO.net connection and Deployment

Because of what seem to be overwhelming difficulties around Entity Framework, I'm in the process of moving to Dapper. 由于Entity Framework似乎存在巨大的困难,因此我正在迁移到Dapper。 I have an application that uses both a remote MS SQL Server database and a small local database (SQLite). 我有一个使用远程MS SQL Server数据库和小型本地数据库(SQLite)的应用程序。 Dapper against the MS SQL Server database is working great, but for some reason I can't get SQLite connection working. 针对MS SQL Server数据库的Dapper运作良好,但由于某些原因,我无法使SQLite连接正常工作。

From the way I understand it, Dapper simply needs an ADO connection. 从我的理解来看,Dapper只需要一个ADO连接。 I installed a NuGet package “sqlite-net”, and used the following code to create the connection: 我安装了一个NuGet包“ sqlite-net”,并使用以下代码创建了连接:

SQLiteConnection con = new SQLiteConnection(“data source=C:\Data\OneDrive\Data\TestDB.sqlite”);

and

SQLiteConnection con = new SQLiteConnection(“data source=C:\Data\OneDrive\Data\TestDB.sqlite; Version=3”);

Neither one of these work and they throw an exception “Could not open database file”. 这些都不起作用,它们都引发异常“无法打开数据库文件”。 The file SQLite.cs (coming from the NuGet package) threw the error. 文件SQLite.cs(来自NuGet包)引发了错误。

Because of my past problems with deployment, I've hesitated installing the downloaded files from System.Data.sqlite.org. 由于过去的部署问题,我犹豫了如何从System.Data.sqlite.org安装下载的文件。

Please can someone help me? 有人可以帮我吗?

Looking at the nuget package and specifically the SQLite.cs file: 查看nuget包,尤其是SQLite.cs文件:

https://github.com/praeclarum/sqlite-net/blob/master/src/SQLite.cs https://github.com/praeclarum/sqlite-net/blob/master/src/SQLite.cs

I see the following constructor definition (line 180): 我看到以下构造函数定义(第180行):

public SQLiteConnection (string databasePath, bool storeDateTimeAsTicks = true)
            : this (databasePath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create, storeDateTimeAsTicks)
        {
        }

This shows that the first argument is just the path, and should be called like: 这表明第一个参数只是路径,应按如下方式调用:

SQLiteConnection con = new SQLiteConnection(@"C:\Data\OneDrive\Data\TestDB.sqlite”);

The @ sign escapes the \\ characters from being interpreted as character codes. @符号可将\\字符转义为字符代码。 These two issues look like the problem that you have and I would try it out and see if it works. 这两个问题看起来像您遇到的问题,我将尝试一下,看看是否可行。

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

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