The Structure of the project :
There is a modules folder which I need to add the database and make the repository just there,
Other modules and assemblies could use that.
New : Changed it to previous proved state of placing the config file in the root application,
still there are errors.
This post is edited completely.
The Database Location :
location : ….\db\db.sdf (2 levels upper from the sell’s app.config)
The App.Config file
location : modules\ModuleX\ (Formerly)
New Location : Shell\ (Main Project)
New Version :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="MyRecordzContext" connectionString="metadata=res://*...
</connectionStrings>
</configuration>
2 Cases of suspect :
providerName=”System.Data.EntityClient”
LocalDbConnectionFactory
Error Info :
Error Line :
TblMyRecord MyRecord = context.MyRecords.First(w => w.MyRecord == stMyRecord);
Error :
No connection string named ‘MyRecordzContext’ could be found in the application config file.
Goal : How to change the connectionstring , my app.config to make the application work as expected
Here EF 5.0, SQL CE , Prism, WPF, MVVM, C# were used
Error :
Error :
The type initializer for ‘System.Windows.Application’ threw an exception.
Appears as the application runs.
The error seems to be before any build.
Stack Trace :
PresentationFramework.dll!System.Windows.Application.Application()
Xz.Shell.exe!Xz.Shell.App.App()
Xz.Shell.exe!Xz.Shell.App.Main()
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args)
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state)
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart()
[Native to Managed Transition]
Here’s my hunch: ModuleX is the DAL project, which is referenced from another project (probably a Web, Windows Forms or Console application) that we’ll call the Startup Project.
If this is the case, then the App.Config file in the DAL project is not used.
There are 2 solutions:
You could specify the connection string in the Startup Project for it to be taken into account. This means that you need to add the
<connectionStrings>...</connectionString>tag in:Alternatively, you could define this connect string in the machine.config file and that will make it available for any .NET application running on that particular machine.
The connection string that’s in the DAL project is not used at runtime. I think it’s only used by the EF designer.