No connection string could be found in the application config file (But it Does Exist) - entity-framework

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="data source=localhost\MyDB;initial catalog=MyDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" 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.

If your project is published in a folder on IIS, and a config file exists in an uppermost folder, those values may be conflicting.
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

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.

Related

Web.config file for the contents and Scripts folder not copied while doing an msbuild to get the build package

I am working on a asp.net mvc2 project which has Contents folder containing images,css files and Scripts folder containing all the js libraries and files used in the project. I have a web.config file containing the code for enabling caching for the contents present within the Contents and Scripts folder as mentioned below:
Web.config:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<!--Caching-->
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" cacheControlCustom="must-revalidate"/>
<!--<clientCache cacheControlMode="UseExpires" httpExpires="Tue, 31 Dec 2030 12:00:00 GMT"/>-->
</staticContent>
</system.webServer>
</configuration>
I am using msbuild to get a package ready for deployment. I see the package is built successfully containing the MSI which I install in the server. After installing the MSI I see that there is no web.config present within the Contents and Scripts folder in the server.
I tried setting Copy to Output Directory = Copy Always in the properties section of the web.config file but still I don't see it in the Contents and Scripts folder in the server.
Can anyone help me to fix the issue?
Thanks & Regards,
Santosh Kumar Patro
From your question I assume you are building your MSI with the Visual Studio Web Setup Project. In that case, you also need to make sure your extra web.config files are included in the "File System" tab view of your installer project. Normally those would be part of "Content Files".

Is there anyway to locate the configuration file in another project?

I'm using entity framework. When an edmx file is generated, the connection string appears in the app.config file.
Is it possible to locate the configuration file in another project? Or, let the edmx file use another project's app.config's connection string?
.NET application uses configuration file of executed assembly. .NET IIS hosted application use web.config. Simply move your connection string to the correct configuration file. That is a correct solution to do that. Otherwise you will have to open another configuration file manually, get the connection string and pass it to context in your code.

tomcat server giving issues to run the application

I am trying to run the application. just i installed the tomcat and netBeans.
It is giving following error. if i try to give build alone,,, build is successful. but i am unable to deploy in server ...
Created dir: D:\Test\build\generated\src
Created dir: D:\Test\build\generated\classes
Compiling 1 source file to D:\Test\build\generated\classes
Undeploying ...
undeploy?path=/excelRD
OK - Undeployed application at context path /excelRD
In-place deployment at D:\Test\build\web
D:\Test\build\web\META-INF\context.xml (The system cannot find the file specified)
D:\Test\nbproject\build-impl.xml:686: The module has not been deployed.
Please do needful
The error message seems clear you need a file context.xml in your project.
In a regular apache project created with Netbeans, you have in the directory Web Pages an other directory names META-INF and in this directory the file context.xml.
Try to respect this architecture. The minimal context.xml contant is :
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/excelRD"/>
He may also be seeing an issues I've seen on NetBeans for years. You have a perfectly valid context.xml file that can't be found by NetBeans during deployment. If you open the file, touch it in anyway (type in a character, delete that character, then save), the problem goes away. I've had this happen so many times that I've gotten in the habit of always touching the context.xml file before I deploy.

NUnit GUI Runner Multiple Configuration Files

I created a test project using a web.config file by renaming it to same name as the project, copying it to the bin folder and setting the Configuration File Name of the NUnit GUI runner to the name of my config file. Now I want to add more assemblies to this project but the problem here is each assembly has it's own web.config file.
How can I set the configuration files for the assemblies because I need to get my connection strings from these config files and considering when loading multiple assemblies they need to be in the same directory
While I feel that using config files for NUnit tests is a no-no (it's an integration test, in that case, I assume), there are various approaches you can try:
Put all your different connection strings under web.config in the connectionstrings section, with different keys. Access them via the System.Configuration classes.
For each project or DLL you can add an app.config file where you can store assembly specific information. This will be renamed as ProjectName.dll.config once compiled. Again you can access the contents of this file using System.Configuration
Create a new assembly that simply loads all these connection strings from a single file. And then access this assembly
If you are loading different web applications into the same directory (as you're saying you're accessing web.config files -- which means web applications) then you're making your life difficult. Each application has to have their own folder and virtual directory, and a web.config specific to only that application.

Web.config values passed through tiers

I have a .NET 2008 solution with a project that acts as WCF Service host. That project has a web.config file with settings that will be replaced by the installer when the project is complete. Those setting are components that make up the connection string and a few others.
This WCF project references a Business Logic project(class library which implements service code) which in turn references a DAL project which uses the Entity Framework.
What I would like to know is how can I get the values in the web.config in the WCF project to the DAL? Without using any relative paths that I have seen with OpenMappedExeConfiguration. I need to build up the connection string in the DAL based on the setting in the web.config file.
Thanks for your answers.
I`m storing shared things like connection strings in 1 folder, which even is not under folder where source code lives. In DAL tier i just use ConfigurationManager to pick it up.
In project, which starts application (in your case, it`s WCF project), i add "ConnectionStrings.config" file from my external "config" folder AS A LINK (in visual studio, press 'add an existing item' -> choose item -> next to "Add" button is an arrow where this option lives). Then i just set it through that file properties (click on file in solution explorer -> press F4) as a content of project and that it should be copied once again if modified to deploy folder. Then i add a new app.config file to project, which includes "ConnectionString.config".
Source of connectionstrings.config:
<connectionStrings>
<add name="MyConnectionString"
connectionString="Data source=tralala"/>
</connectionStrings>
Source of app.config in WCF project:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings configSource="ConnectionStrings.config"></connectionStrings>
</configuration>
I'm not sure that this is the best approach. But so far so good.
Unfortunately, the answer to your question is "copy and paste". This has always been true.
The closest thing to an exception to this rule is the "new" .NET 2.0 Settings files. Because the structure and default values for these are part of the assembly defining the component, the component can, upon startup, cause the default values to be written to the applications configuration. I imagine one could couple that with a piece of code to work with installutil to cause the defaults to be written out before the containing application is ever started, leaving the defaults in the config file to be edited before the application is used for the first time.