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?

Community
  • 1
  • 1
Nuts
  • 2,755
  • 6
  • 33
  • 78
  • Possible duplicate of [how to deploy sqlite with .Net](http://stackoverflow.com/questions/3728175/how-to-deploy-sqlite-with-net) – NoWar Mar 03 '16 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. – mlt Aug 31 '16 at 01:51
  • [The linked approach for ClickOnce](http://stackoverflow.com/a/23896952/673826) seems to work for me. – mlt Aug 31 '16 at 02:01

1 Answers1

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>
avs099
  • 10,937
  • 6
  • 60
  • 110