[英]Inno setup installation
I made a WPF app which I can install on other computers, everything works fine except for database access. 我制作了一个WPF应用程序,可以将其安装在其他计算机上,除了可以访问数据库之外,其他所有功能都可以正常运行。 Currently, I have a sqlite database on my computer and the connection string for this database is specific to my computer.
当前,我的计算机上有一个sqlite数据库,该数据库的连接字符串特定于我的计算机。
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 ! 提前致谢 !
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.
本质上,这是一个XML文件,您可以使用它存储应用程序的某些值,并且即使在部署应用程序后也无需重新编译即可更改它。
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: 在应用程序的开始,您可以轻松地使用ConfigurationManager类从App.config文件中加载连接字符串,如下所示:
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 (eg Entity Framework retrieves a connection string from App.config automatically if the name is the same as the class that implements
DBContext
). 请注意,如果您正在使用某些对象关系映射器(例如Entity Framework和NHibernate),则甚至不必手动检索连接字符串(例如,如果名称相同,则Entity Framework会自动从App.config中检索连接字符串)作为实现
DBContext
的类)。
If you have any further questions, please feel free to ask. 如果您还有其他疑问,请随时提问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.