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.

5
  • 1
    You need to give more details otherwise not many people on earth will be able to help you Commented Sep 28, 2019 at 21:06
  • 1
    I think now it's better, do you have answer? Commented Sep 28, 2019 at 21:14
  • 1
    "then shuts down". This usually mean you have an uncaught exception somewhere, see stackoverflow.com/questions/8823393/…. 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 minimal reproducible example, which can be compiled and tested by others. Commented Sep 28, 2019 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 Commented Sep 28, 2019 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? Commented Sep 28, 2019 at 22:12

1 Answer 1

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";
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for the answer. I don't create database inside the app, I only fetch data from it and store data in it
you want your setup to copy your database file for all installations?
If yes, then try using Inno Setup
with this you can specify a folder (bin/release) that will be deployed with your app. place your database in the bin folder. Use an environment generated file path to connect to it.

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.