4

I need to deploy SQLite file with WPF application.

  • Deployment technique is ClickOnce.
  • Entity Framework is included to work with the database.

I'd like to have a shortlist what must be considered when deploying the application that includes a SQLite database file in it.

So far, I have referenced and set Copy Local to True for:

  • System.Data.SQLite
  • System.Data.SQLite.Linq

.and I have two interops where Copy to Output Directory I left to be the default Copy Always

  • SQLite.Interop.dll (x86)
  • SQLite.Interop.dll (x64)

In the app.config file I have:

<applicationSettings>
    <MyApp.MySettings>
       <setting name="connStrSQLite" serializeAs="String">
           <value>data source="C:\MyFolder\MySQLiteFile.sqlite3"</value>
       </setting>
    </MyApp.MySettings>
</applicationSettings>

and

<connectionStrings>
    <add name="MyEntities" connectionString="metadata=res://*/Model.ORM.MyModel.csdl|res://*/Model.ORM.MyModel.ssdl|res://*/Model.ORM.MyModel.msl;provider=System.Data.SQLite;provider connection string='data source=&quot;C:\MyFolder\MySQLiteFile.sqlite3&quot;'" providerName="System.Data.EntityClient" />
</connectionStrings>

I suppose in the app.config the paths are not working on deployed application since they are referring to my local folder now. How to modify them?

Then, I checked for example from here SQLite deployment for .net application that the following should be added to app.config file.

<system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite" />
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
    </DbProviderFactories>
</system.data>

Anything else?

3
  • Possible duplicate of how to deploy sqlite with .Net Commented Mar 3, 2016 at 12:00
  • So how to automatically include those interops? The only answer doesn't seem to address the Q though is accepted. @Dimi This is not a duplicate as it deals with other deployment method. Commented Aug 31, 2016 at 1:51
  • The linked approach for ClickOnce seems to work for me. Commented Aug 31, 2016 at 2:01

1 Answer 1

2

regarding your connection string - for ClickOnce installation you should use |DataDirectory| substitution instead of full path - runtime will automatically convert this into proper local path:

<connectionStrings>
    <add name="MyContext" connectionString="DataSource=|DataDirectory|Mydb.sdf" providerName="System.Data.SqlServerCe.4.0"/>
  </connectionStrings>
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.