0

I've created a C# WPF application which interacts a SQLite database. I want to create installation file so as to be able to install the app on another computer. Does anyone know how to deploy C# WPF app with SQLite database, I've created a setup file by using ClickOnce, but when I run the app and do something with the app which requires fetching data from database, the shuts down.

miki1307
  • 147
  • 9
  • 1
    You need to give more details otherwise not many people on earth will be able to help you – BenKoshy Sep 28 '19 at 21:06
  • 1
    I think now it's better, do you have answer? – miki1307 Sep 28 '19 at 21:14
  • 1
    "then shuts down". This usually mean you have an uncaught exception somewhere, see https://stackoverflow.com/questions/8823393/keep-an-application-running-even-if-an-unhandled-exception-occurs. You can try to react to such an exception, but it makes more sense to fix the issue why the exception occured. You need to add error handling to your code. Please [edit] your question to include your full source code you have as a [mcve], which can be compiled and tested by others. – Progman Sep 28 '19 at 21:15
  • 1
    @miki1307 - the details you added are not enough for people to answer. Please provide a min reproducible example as per Progman's comment – BenKoshy Sep 28 '19 at 22:00
  • 1
    @BKSpurgeon I understand, but my application is large, and know I want to make an installation file so I thought people have experience with that, it's something universal. I have C# WPF application with SQLite database and my question is how to make installation file? – miki1307 Sep 28 '19 at 22:12

1 Answers1

3

I don't think it's all about making the installation file. I think, the application crashes because the software can't find the database. If you develop your software in such a way that, it creates the database (if it doesn't exit) on startup, the way you create the installation file won't be a problem. Here is what I mean:

//use an environment generated file path.
public string _dataBasePath = $@"{ System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData)}\databaseName.db";

Using an object relational mapper like NHibernate. You can override OnStartUp and create your database:

   // In the App.xaml.cs class
    private override void OnStartup(StartupEventArgs e) {
        base.OnStartup(e);
        BuildSchemaAction(config);
    }
    private void BuildSchemaAction(Configuration config) {
        new SchemaExport(config).Create(false, !File.Exists(_dataBasePath));
    }
    protected Configuration config = new Configuration();

The database file (since it is SQLite) will not exist, so it will be created. Subsequently, it will not be created. The _dataBasePath field will be the path in the connection string, in order to access the database in the path it was created.

x.ConnectionString = $"Data Source={_dataBasePath};version=3";
Ndubuisi Jr
  • 461
  • 6
  • 13