Connection string in app.config in a class library

血红的双手。 提交于 2020-01-01 09:32:46

问题


I am creating solution and inside I have three projects:

  1. A WCF Service Library Project

  2. A DataAccess Project (Class Library)

  3. A Web site for hosting WCF service

The implementation of the service is on the project # 1, but in order to access the DataBase I use a second project that implements the data access using a class library project.

That problem is in order to get data access I need to configure a connection string, but that connection string must be configurable in a production environment, I meant in production I am going to deploy the site, which is a very simple project that contains only a reference WCF Service Library Project then a guy from database department will configure the connection string.

In development I have an app.config on the data access project but when I do the release that app.config is embedded on the dll.

Any ideas how can we achieve our purpose


回答1:


The connection string in your app.config (data layer) is not embedded in the dll.

If you look in the app.config file in your data layer project, you will probably have a connectionStrings section. you need to put the connectionStrings in the web.config of your WCF service website.

This can be configured in your production environment.




回答2:


The connection string must be in the application configuration file of the executing assembly. This means that you can provided the configuration file for your assembly along with the assembly itself but anyone who wants to use your assembly must update their configuration file to include the values that your assembly relies on.




回答3:


I had a mistake, I was using a different name on the web.config of the WCF site, I just copy the the exact part of the app.config to the web.config and its working now.

Thanks for your help



来源:https://stackoverflow.com/questions/2548726/connection-string-in-app-config-in-a-class-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!