Answered by:
Getting a "no connection string ... could be found in the application config file" error, but don't understand why

Question
-
I'm working on a WPF app I wrote about a year ago, as it needs some changes. In getting back into it I remember that I had a problem, back then, which I wasn't able to resolve but the app still compiled and I was able to deploy it. It's been working fine since (well, until some database changes were recently made causing me to have to make changes to the app).
Like I said, about a year ago I was having problems with it and thought the problems were in WPF. However I was told by Microsoft technical support that the problem is really an entity framework problem. (Getting a "No connection string named '' cound be found in the application config file" error, and I don't understand why.) So now I'm returning to make the necessary enhancements to the app, but would love to know why this error still shows up. The error says:
"No connection string named 'PrismSpecMap' could be found in the application config file."
As I said a year ago, that makes no sense at all. There most certainly is a connection string named 'PrismSpecMap' and it is in the App.Config file in the connectionStrings section.
Since the WPF team believes the problem is with EF, then why does EF think there's no connection string, but then it uses it with no problems whatsoever? There are only 2 projects in this solution, the application itself and a MS Test unit test project. The error is occurring in the application project.
Rod
Wednesday, June 15, 2016 5:16 PM
Answers
-
Ok,
Can you locate <ConnectionStrings> to above the other tags so that it be the first tag under the Configuration tag.
Try again and feed me back if still not working
Thanks Mahmoud
- Proposed as answer by Zhanglong WuMicrosoft contingent staff Tuesday, June 28, 2016 2:32 AM
- Marked as answer by Herro wongMicrosoft contingent staff Thursday, June 30, 2016 1:57 AM
Friday, June 17, 2016 3:01 PM
All replies
-
I am not too sure if you have a same issue as I do.
Make sure your connection string is with your Start Up Project.
chanmm
chanmm
Thursday, June 16, 2016 1:59 AM -
Hi Rod at Work,
According to your error message, it seems that EF couldn't find the connection string named 'PrismSpecMap'. Please check if your custom DbContext connection string is the same as app.config's connection. like this:
#App.config
<connectionStrings> <add name="DefaultConnection" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\SchoolMate.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient" /> </connectionStrings>
#DbContext
public SchoolContext() : base("DefaultConnection") { }
Best regards,
Cole Wu
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Thursday, June 16, 2016 2:57 AM -
App.Config only gets used in debug mode. At runtime for a solution that creates an exe file, then all app.config files in other projects for the solution and their information must be copied to the app.config of the exe project as that is the root project. The app.config in the root project is copied over to a runtime config called programname.exe.config, which is the runtime config file where .NET is going to look at for config information that must be in the same folder as the programname.exe itself resides.
Programname.exe.config where is it and you can use an editor to look at the file content?
Thursday, June 16, 2016 2:23 PM -
Hi Rod at Work,
According to your error message, it seems that EF couldn't find the connection string named 'PrismSpecMap'. Please check if your custom DbContext connection string is the same as app.config's connection. like this:
#App.config
<connectionStrings> <add name="DefaultConnection" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\SchoolMate.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient" /> </connectionStrings> #DbContext
public SchoolContext() : base("DefaultConnection") { }
Best regards,
Cole Wu
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.They are the same. Here's what I've got in the App.Config file:
<connectionStrings> <add name="PrismSpecMap" connectionString="data source=...."/> </connectionStrings>
and here's what's in my custom DbContext connection:
public partial class PrismSpecMapClass : DbContext { public PrismSpecMapClass() : base("name=PrismSpecMap") { }
Rod
- Edited by Rod at Work Thursday, June 16, 2016 5:35 PM corrected the HTML
Thursday, June 16, 2016 5:34 PM -
Hi Rod at Work,
According to your error message, it seems that EF couldn't find the connection string named 'PrismSpecMap'. Please check if your custom DbContext connection string is the same as app.config's connection. like this:
#App.config
<connectionStrings> <add name="DefaultConnection" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\SchoolMate.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient" /> </connectionStrings> #DbContext
public SchoolContext() : base("DefaultConnection") { }
Best regards,
Cole Wu
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.They are the same. Here's what I've got in the App.Config file:
<connectionStrings> <add name="PrismSpecMap" connectionString="data source=...."/> </connectionStrings>
and here's what's in my custom DbContext connection:
public partial class PrismSpecMapClass : DbContext { public PrismSpecMapClass() : base("name=PrismSpecMap") { }
Rod
All of this is kind of questionable if the information is not in the programname.exe.config where .NET is looking for config information, which is the runtime config file.Thursday, June 16, 2016 9:47 PM -
Hi,
Can you check the location of the connectionstrings tag in the app.config file? Is it on the top Or there is a ConfigSettings tag?
Make it at the root of your file then try again. If it is on top already try to locate it after ConfigSettings and try
Hopefully this solves your problem.
Thanks Mahmoud
Thursday, June 16, 2016 10:24 PM -
Hi Rod at Work,
According to your error message, it seems that EF couldn't find the connection string named 'PrismSpecMap'. Please check if your custom DbContext connection string is the same as app.config's connection. like this:
#App.config
<connectionStrings> <add name="DefaultConnection" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\SchoolMate.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient" /> </connectionStrings> #DbContext
public SchoolContext() : base("DefaultConnection") { }
Best regards,
Cole Wu
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.They are the same. Here's what I've got in the App.Config file:
<connectionStrings> <add name="PrismSpecMap" connectionString="data source=...."/> </connectionStrings>
and here's what's in my custom DbContext connection:
public partial class PrismSpecMapClass : DbContext { public PrismSpecMapClass() : base("name=PrismSpecMap") { }
Rod
All of this is kind of questionable if the information is not in the programname.exe.config where .NET is looking for config information, which is the runtime config file.Here's what's in the programname.exe.config:
<connectionStrings> <add name="PrismSpecMap" connectionString="data source=..." /> </connectionStrings>
Same as what's in the App.Config file.
Rod
Friday, June 17, 2016 2:17 PM -
Hi,
Can you check the location of the connectionstrings tag in the app.config file? Is it on the top Or there is a ConfigSettings tag?
Make it at the root of your file then try again. If it is on top already try to locate it after ConfigSettings and try
Hopefully this solves your problem.
Thanks Mahmoud
No, its more towards the bottom. It's within the <configuration> tag. At the same level, but before <connectionStrings> is: <configSections>, <startup> and <entityFramework>. There are no other nodes in the App.Config file that are sister nodes to <connectionStrings>.Rod
Friday, June 17, 2016 2:25 PM -
Ok,
Can you locate <ConnectionStrings> to above the other tags so that it be the first tag under the Configuration tag.
Try again and feed me back if still not working
Thanks Mahmoud
- Proposed as answer by Zhanglong WuMicrosoft contingent staff Tuesday, June 28, 2016 2:32 AM
- Marked as answer by Herro wongMicrosoft contingent staff Thursday, June 30, 2016 1:57 AM
Friday, June 17, 2016 3:01 PM -
Hi Mahmoud,
I'm sorry its taken me so long to get back to this.
I just did as you suggested. I moved the <connectionStrings> section in the App.Config file to be the first section in the <configuration> section. Unfortuntately that made it worse. When I tried running my application then, I got the following error message:
System.TypeInitializationException was unhandled
HResult=-2146233036
Message=The type initializer for 'System.Windows.Application' threw an exception.
Source=PresentationFramework
TypeName=System.Windows.Application
StackTrace:
at System.Windows.Application..ctor()
at SpecMapException.App..ctor()
at SpecMapException.App.Main() in d:\Src\SpecMapException\SpecMapException\obj\Release\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at System.Activator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.TypeInitializationException
HResult=-2146233036
Message=The type initializer for 'System.Windows.Navigation.BaseUriHelper' threw an exception.
Source=PresentationFramework
TypeName=System.Windows.Navigation.BaseUriHelper
StackTrace:
at System.Windows.Application.ApplicationInit()
at System.Windows.Application..cctor()
InnerException: System.TypeInitializationException
HResult=-2146233036
Message=The type initializer for 'MS.Internal.TraceDependencyProperty' threw an exception.
Source=WindowsBase
TypeName=MS.Internal.TraceDependencyPropertyHowever, if I placed it after the <configSections> section, then I was able to run it. But I still get that error message in Visual Studio 2013.
I did make a new discovery yesterday when I was working on this app. I discovered that if I close the .xaml in VS 2013, the error magically goes away. If I have it open in VS 2013, I get the error. Why would Visual Studio do that?
Rod
Friday, July 1, 2016 3:00 PM -
Hi Rod,
No worries. If what you say is related to the XAML. Are you able to run the application from the debug folder? You can try to run it when the Visual Studio is closed.
Also, do you have any edition of Visual Studio rather than 2013? If you have, please try open the project and test it in case XAML is open or not. We need to make sure if this is related to version of Visual Studio or not.
If the issue is gone, we would suspect the version you have and you may need to repair it.
Please let me know your findings
Thanks, Mahmoud
Friday, July 1, 2016 10:19 PM -
Good idea. I'm off until Wednesday of next week, so I'll try it when I get back.
Rod
Sunday, July 3, 2016 1:09 PM