简体   繁体   中英

what should be included on the app.config file of executable referencing other exe containing an app.config file

I am confused about how the app config file is used. I have a program that connects to a SQL server database , retrieves data from a specific table. I am using LinqToSql classes to do this. When I follow the wizard at the end the connection string gets placed in the app.config file .

I then plan to use that program as a class library so I add a reference to that exe from a different executable which is a wpf application. On that wpf application I have to place an app.config file containing the connection string in order for the program to work.

So far I understand everything. Now the part I am confused is why I do not have to copy also the settings located in the app.config file as well in order for the program to work? which settings are OK to be on the referenced executable and which ones are not. For example I know that the connection string should be on the app.config file of the wpf application. But the user settings :

在此处输入图片说明

app.config: 在此处输入图片说明

can be on the app.config of the referenced executable.

In summary why did I have to move content from the referenced executable's app.config file to the app.config file of the wpf application and I did not had to move other content from the referenced executable app.config file?

By default, the config file that is used is that of the executing process/program. Since your WPF app runs as its own executable, the config settings need to exist in its config file.

As for the other settings, your WPF app probably doesn't need them.

As a side note, it's usually a better practice to have a WPF/client app hit a service instead of going directly to the database itself. That would mean that the connection string would go in the config file of the service at that point. And the WPF app would just ask the service for the information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM