Mehdi Souregi
Mehdi Souregi

Reputation: 3265

Setting connection string after publishing on IIS Server

I have two projects, an asp.net MVC project called Home and a c# class library project called Home.Dao.

When publishing the Home project in IIS server, I can only find these files (web.config, Hom.Dao.dll, ... etc ) there is no app.config published. My problem is I cannot set the connectionstring after publishing. So I have two questions in mind :

  1. How is it possible to set connectionstring from web.config so this connectionstring can be used on Home.Dao
  2. Is possible to publish also the app.config ?

Upvotes: 0

Views: 965

Answers (1)

Sefe
Sefe

Reputation: 14017

To answer your questions:

  1. It is not only possible, it is necessary to set the connection string from web.config
  2. You could copy the app.config to the output directory, but that wouldn't be of much use to you.

To explain why:

Configuration files are only created for the top-level application. For web applications this is the web.config file which is copied to the output directory. For executables the app.config is renamed to -executable name-.exe.config. Configurations are only read from the top-level application config. All settings you need have to be there. So if you transfer your connection string to your web.config, you're good.

Upvotes: 2

Related Questions