Hi,
I am using ASPNet Core, EntityFramework 6 CodeFirst.
I have a BaseController which will get the User Information by accessing the Entity Framework 6 Code First database. This will be inherited for all controllers in the app. On the class BaseController, event "OnActionExecuting", line "using (SVPData context1 = new SVPData())", I am running into error:
error: "No connection string named SVPData could be found in the application config file."
Project: SVPWebApp
appSettings.json
"ConnectionStrings":
{
"DefaultConnection":"Server=devserversql001;Database=SVP;Trusted_Connection=True;MultipleActiveResultSets=true"
}
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddScoped<SVPData>(_ => new SVPData(Configuration.GetConnectionString("DefaultConnection")));
services.AddMvc();
services.AddMemoryCache();
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(15);
options.CookieName = ".MyCoreApp";
});
}
vwSVPRecordController.cs
public class vwSVPRecordController : BaseController
{
// GET: /<controller>/
private readonly SVPData db;
public vwSVPRecordController(SVPData context)
{
db = context;
}
}
BaseController.cs
public class BaseController : Controller
{
const string SessionKeyUser = "_User";
UserAuthorizationDTO user;
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
UserAuthorizationDTO uaDTO = GetUserDTO();
if (uaDTO == null)
{
string sUserName = System.Environment.UserName;
using (SVPData context1 = new SVPData())
{
}
}
}
}
How come before I added the BaseController, it was not having an error reading off the SVPData db in the vwSVPRecordController class? How can I get and check the user info for the BaseController?
Please note that SVPData is in a different project. It's app.config is this:
Project: SVPData
app.config
<configuration>
<connectionStrings>
<addname="SVPData"connectionString="data
source=devserversql001;initial catalog=SVP;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"providerName="System.Data.SqlClient"
/>
</connectionStrings>
</configuration>
I appreciate your input!
Thanks,
tinac99