0

I have a ASP.NET MVC solution with 2 projects: DAL and web project. I used to connect to my SQLite database using local file path in connection string of both projects' web.config files:

Web.configs of DAL and Web projects:

<add name="DBEntities" connectionString="metadata=res://*/Models.Model.csdl|res://*/Models.Model.ssdl|res://*/Models.Model.msl;
provider=System.Data.SQLite;
provider connection string='data source=&quot;C:\Users\Admin\Documents\Visual Studio 2013\Projects\Myproj\Myproj.db3&quot;'" 
providerName="System.Data.EntityClient" />

Everything was working fine, and then I needed to change connection string using DataDirectory, so that I could correctly deploy the website. I added the db file into App_Data folder of WEB project and both web.configs changed to:

<add name="DBEntities"
connectionString="metadata=res://*/Models.Model.csdl|res://*/Models.Model.ssdl|res://*/Models.Model.msl;
    provider=System.Data.SQLite;
    provider connection string='data source=&quot;|DataDirectory|\Myproj.db3&quot;'" 
    providerName="System.Data.EntityClient" />

Now, I can connect to the db extract data via code, but I cannot open database in server explorer and use designer, the error is: "Unable to open database file".

I would appreciate any help!

Gyuzal
  • 1,581
  • 10
  • 52
  • 99
  • Check out the answer here:http://stackoverflow.com/questions/10292875/unable-to-open-database-sqlite-in-asp-net-mvc3-app-using-spring-net this may help or at least give you some clues – Anonymous Sep 04 '15 at 20:59
  • I'm using DataDirectory as suggested, but my problem is only with server explorer designer, because db is accessible via code. – Gyuzal Sep 04 '15 at 21:15

1 Answers1

0

I used like this. If you want you can try.

private readonly static string ConnectionKey = @"C:\Users\Mehmeto\Documents\Visual Studio 2015\Projects\......\bin\myDB.sqlite";

    public static SQLiteConnection GetConnection()
    {

        SQLiteConnection conn = new SQLiteConnection("Data Source=" + ConnectionKey + ";Version=3;", true);
        return conn;
    }