Inno setup installation

369 Views Asked by At

I made a WPF app which I can install on other computers, everything works fine except for database access. Currently, I have a sqlite database on my computer and the connection string for this database is specific to my computer.

I am able to run my application on other computers if I manually create the same directory structure where the database is stored.

How can I make an installer which allows me to choose the destination of the database?

How can I get the new connection string for this new database?

Thanks in advance !

1

There are 1 best solutions below

0
On

I assume that you hardcoded your connection string into your application - instead, you could save your connection string in an Application Configuration File. This is essentially an XML file that you can use to store certain values for your application and that you can change even after the app is deployed without recompiling it.

At the beginning of your application, you can easily use the ConfigurationManager class to load a connection string from the App.config file like this:

var connectionString = ConfigurationManager.ConnectionStrings["myDBConnectionString"];

You can then pass this connection string to your objects that depend on them. Please note that if you're using certain Object-Relational-Mappers like Entity Framework and NHibernate that you might not even have to retrieve the connection string manually (e.g. Entity Framework retrieves a connection string from App.config automatically if the name is the same as the class that implements DBContext).

If you have any further questions, please feel free to ask.