0

Because of what seem to be overwhelming difficulties around Entity Framework, I’m in the process of moving to Dapper. I have an application that uses both a remote MS SQL Server database and a small local database (SQLite). Dapper against the MS SQL Server database is working great, but for some reason I can’t get SQLite connection working.

From the way I understand it, Dapper simply needs an ADO connection. I installed a NuGet package “sqlite-net”, and used the following code to create the connection:

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.

Because of my past problems with deployment, I’ve hesitated installing the downloaded files from System.Data.sqlite.org.

Please can someone help me?

2
  • Please edit your question to remove the large quantities of text that are fully unrelated to your problem/question. Commented Apr 28, 2015 at 4:10
  • If one of the answers sufficiently addressed your question, you may want to mark it as the answer, so that your question can be removed from the "unanswered questions" list. Please refer to What should I do when someone answers my question?. Commented Apr 28, 2015 at 23:57

1 Answer 1

2

Looking at the nuget package and specifically the SQLite.cs file:

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

I see the following constructor definition (line 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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this seemed to work. Sometimes the simplest items are the hardest to see. Now that I have this working, with your help, I will work on the deployment to user machine. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.