No connection string named '' could be found in the application config file - c#

I have a class library with a method that takes a string and returns an xml document. This library references another project - containing edmx models generated with EF6 db first.
I realize that my connection strings from the EF project must be moved into the "executing" application config file - this is fine in development as I have created a simple web client as my startup project and it's web.config contains the necessary connection strings.
When I deploy this solution to my QA server, the "executing" application is actually a VB6 app and I am getting this error. I have no idea what application config file is being used in this case.
Any suggestions?

Related

ASP.NET MVC project web.config and app.config files

When creating an ASP.NET MVC project, a web.config file gets generated automatically and is used for all the connection strings and dll versions relevant to the solution.
I've added a new project to the solution for handling data operations using Entity Framework and can see that it has it's own app.config that gets created as well.
Previously, all data and web was on the one ASP.NET project and now I've split them up into two different projects so I can have the web project just have web components and data project have database connections using Entity Framework.
Initially it looked like the app.config of the data project would require the connection strings to the database be present as well, but it looks like the data project can connect fine to the database using the connection strings from the web.config file.
I've tried removing the app.config file completely from the data project and it looks like the solution runs even without it.
Are there any special reasons the app.config file exists in an ASP.NET MVC project or can this file be safely deleted without affecting the website?
For example, I tried putting in 2 different connection strings, one in web.config and a different one in app.config. When accessing the site, it looks like only the connection strings and app variables from the web.config file is used.
Is there some sort of hierarchy that gets used where the app.config details will override the web.config details?
In .Net, there only have three types of project: windows application, console application and class library.
The app.config will be generated automatically with the first two type applications, and it will be used while the application running;
For the web site/application/services, the web.config will be generated and used while accessing web pages. But actually, the web site/application/services are class library type.
In your case, the Data project might be created as a console/windows application, so the app.config will be generated. So you should change the Data project to class library and add a project reference in the Web project, then you can delete app.config safely.
To change project type:
Right click the Data project -> Property -> Application in the left panel -> Output type -> Class Library
To add project reference:
Right click the Web project -> Add -> Reference.. -> Projects in the left panel -> check the Data project -> OK
Finial, the reason why only the connection string in web.config is being used is: the Data project is treated as a class library and it will fetch the configurations from web.config at the runtime. And if you run the Data project alone, it will fetch the configurations in app.config instead.
Both are used to configure the project, the only difference is the type of project.
From the source
Web.Config is used for asp.net web projects / web services. (or Say Web application)
App.Config is used for Windows Forms, Windows Services, Console Apps and WPF applications (or say window application)
So might be your second project for data is window or console-based, that's why created.
Until any file in a project, you do not have the reference in other files, you can remove and run the project.
Ideally connection string at your main project and give the reference in the data project which is handling the single connection string in the solution or in multiple projects.
https://www.c-sharpcorner.com/UploadFile/8a67c0/web-config-vs-app-config-vs-machine-config/

Forcing Entity Framework and ASP.MVC to use the connection string from app.config of another assembly

Set & settings:
I use Entity Framework 5 and have a dll project with edmx file. In this project I have App.config with connection string for the EF model. I have also second project, ASP.MVC 4 web application which is a startup project. It references the database project. Important thing is - db is Oracle and EF uses Oracle custom providers.
Problem:
If I place my connection string in the ASP.MVC startup project is works fine. It's common advice to do this. But I don't want to. I don't see reason why I should. How can I force MVC/EF to find the connection string in App.config of the external library (which as a matter of fact is a data access layer)?
App.Config is used by WinForms, WPF and executable applications.
Web.Config is used in IIS (and is able to set IIS environment specific configurations)
It seems no App.Config will ever be merged to the Web.Config (source):
In using an App.config, file the configuration system merges the
App.config file with content of the Machine.config file when the
application starts and the configuration is applied. This mechanism
allows machine-wide settings to be defined in the Machine.config file.
The App.config file can be used to override the settings of the
Machine.config file; you can also lock in the settings in
Machine.config file so that they get used. In the Web.config case, the
configuration system merges the Web.config files in all directories
leading up to the application directory into the configuration that
gets applied. For more information about configuration and the setting
priorities, see topics in the System.Configuration namespace.
Perhaps you'll find a solution more appropriate to your needs by using Application Configuration Files.
Finally, after facing multiple issues, I've decided to move connection string of DAL into the Web.config of the web application. I was convinced by some arguments you can read here in the post of Chris Ammerman.

C# linq to sql access app.config file

I am having a linq to sql problem with a C# 2010 windows form application when it is changed to a dll and accessed by other applications. The purpose of the calling the code as a dll is for performance reasons and to share the code accross multiple applications.
When the application is on its own, it runs fine.
Basically when the linq to sql was dragged to the desktop, a default linq to sql connection was setup by the .net framework. However I changed the *.designer.cs to use the system.configuration namespace,
added a reference to the system.configuration namespace, and changed the default linq to sql connection to use the database connection obttained in app.config file. I also removed any refernces to the default database connections in the the 'properties or 'settings' section for each project file folder.
Now the problem is the default setting values to the database are reset by the .net framework. Thwe values in the app.config file are no longer being used.
Can you show me code, point me to a reference, and/or tell how I can make this application is the connection string values in the app.config file again?
A dll is run in the the context of the application calling it. It is not an application in its own right, so giving it an app.config file is useless. The configuration settings used by the dll are supplied by the calling application's .config file (it can be an app.config file or a web.config file). In your case, any application using the dll must have the database connection defined its own .config file.

Why is App.config read only from the main project?

I have two c# projects:
1. A DAL project which consists of a sql compact.e database and a .cs file that calls the stored procs after reading the connection string from the project's app.config file.
2.A client project- a simple .cs that uses the DAL project to access the DB and display the results in a simply GUI.
I've ran into some issues with the DAL, since ConfigurationManager.ConnectionString was empty all the time and then I discoverd that if I put the connection string inside the client's app.config then it can read it.
I have two questions:
1. Why does it work that way? Why a file the resides inside the DAL project can only read the client's project app.config file and not it's own?
2. It seems rather silly to add app.config to each client project that connects to the same DAL project, hence to the same DB. How can I have one app.config file mutual to all of my projects? Or how can I make sure that the DAL project's .cs file will read it's own app.config file?
Thanks ahead

Entity Framework connections strings messing up app.config

I'm using Entity Framework inside a DLL.
VS creates a app.config, but when I run the application I receive this exception.
"The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid."
You need to include that connection string in the start up project of your solution. If it is a Asp.Net WebForms/MVC application include that connection string in the Web.Config file or if it is a Windows or Console App include it in App.Config file.

Categories