0

I have a web API project I published to IIS and it complains there is no connection string with a specific name in my config file. I verified there is an entry in my web.config file of the web API project so it must not be picking it up. I was able to run this same web.config file locally using Visual Studio 2013.

I am well aware the referenced start up project must have the connection string and that is the case for me. I verified my web API project has the connection string below (same one I used successfully on my local machine).

<connectionStrings>
    <add name="MyDB" connectionString="metadata=res://*/MyDB.csdl|res://*/MyDB.ssdl|res://*/MyDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost\MyDB;initial catalog=MyDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient"/>
</connectionStrings>

Is it complaining about another config file somewhere else on the server?

I already tried the suggestions in this question with no luck.

Community
  • 1
  • 1
Adam
  • 4,590
  • 10
  • 51
  • 84
  • I am trying to read the web.config during web API startup class WebApiConfig.Register() if that makes a difference? – Adam Apr 24 '15 at 19:02
  • I figured out what it was. I have to access the web.config file from web API startup but Global.asax which invokes the startup registration lives one directory higher so it wasn't finding the file. – Adam Apr 24 '15 at 19:12
  • Please post the Exact Exception, Exception Message, and Exception Stacktrace. – Erik Philips Apr 24 '15 at 19:16
  • This is no longer an issue. It was masking the true issue which is different but related. I opened it up here: http://stackoverflow.com/questions/29856864/reading-the-web-config-file-from-global-asax – Adam Apr 24 '15 at 20:28

2 Answers2

0
  1. If your project is published in a folder on IIS, and a config file exists in an uppermost folder, those values may be conflicting.
  2. If another config file exists, try enabling the option "Remove additional files at destination" when publishing. This option is location under Settings -> File Publish Options
Jacob Heck
  • 53
  • 1
  • 7
  • top folder mapped in IIS contains bin, Global.asax, and packages.config. Inside bin there is only one web.config file. – Adam Apr 24 '15 at 18:31
  • Is IIS on your local or remote machine? You said: "it complains there is no connection string with a specific name in my config file.", can you update the question so we can see a screenshot of this error message? – Jacob Heck Apr 24 '15 at 19:28
0

Inside bin there is only one web.config file -

Your web.config file should be in same folder as Global.asax, packages.config and not in bin folder.

Guanxi
  • 3,103
  • 21
  • 38