1

I want to connect my project to an Sqlite database. So, in my Database Context I have this cunstructor and an Initialize method

    private  DatabaseContext(string cnxString) : base(cnxString)
    {
        Database.SetInitializer<DatabaseContext>(new DatabaseInitialiser());
    }
    public static void initialize(string connx)
    {
        _instance = new DatabaseContext(connx);
    }

and In the program.cs I call Inialize method to set the connexion string

DatabaseContext.initialize("data source=D:\storage.sqlite;");

So, every user can connect to his database by passing his connexion string.

But, when running my application I have this error :

An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.
2
  • 1
    brice-lambson.blogspot.ch/2012/10/… Commented Oct 25, 2013 at 14:20
  • I want to connect to my database without app.config, only with c# code Commented Oct 25, 2013 at 14:33

1 Answer 1

2

You'll need to pass in a SQLite connection object to the base constructor:

private DatabaseContext(string cnxString)
    : base(new SQLiteConnection(cnxString), contextOwnsConnection: true)
{
}
Sign up to request clarification or add additional context in comments.

Comments

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.