I have built a separate data layer which contains my Entity Framework. I made a reference to this separate project in my current project ... I added the following to my current MVC controller:
using SMCD_DataLayer;
[HttpPost]
public ActionResult Login(LoginViewModel lv)
{
var db = new SMCD_DataStoreEntities();
var found = db.Users.Select(x => x.Username == lv.userId && x.Password == lv.passWord).Any();
if (ModelState.IsValid)
{
if (!found)
{
lv.errorMsg = "User ID is invalid!";
}
else
{
return RedirectToAction("IntroPage", "Devices");
}
}
return View(lv);
}
my SMCD_DataStoreEntities lives in SMCD_DataLayer, but this controller lives in SMCD_Portal Project.
on the line var found ... I am getting the following error message:
System.InvalidOperationException occurred HResult=0x80131509 Message=No connection string named 'SMCD_DataStoreEntities' could be found in the application config file.
The connection string lives in the SMCD_Datalayer, even though I am referencing it in my current project, does it need to live in the SMCD_Portal Project?
This is the connection string which lives in the App.config in the SMCD_DataLayer, remember my controller lives in SMCD_Portal
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<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=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<connectionStrings>
<add name="SMCD_DataStoreEntities" connectionString="metadata="res://*/SMCD DataStore.csdl|res://*/SMCD DataStore.ssdl|res://*/SMCD DataStore.msl";provider=System.Data.SqlClient;provider connection string="data source=KARL-LT\SQLEXPRESS;initial catalog=SMCD_DataStore;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
Any .config settings that are used by your application, or used by any referenced assemblies, will generally need to be in the main application's .config file.
The same applies for connection strings.
So put those connection strings in your main application's .config file and you should be alright.
User contributions licensed under CC BY-SA 3.0