c# - Entity Framework 6 - Connection can be made from package manager but not from Web API project -


my solution consists of 2 projects. 1 web api/angular2 application, , other data access layer interfaces entity framework. web application project references data layer project in order create/retrieve data.

i getting following error when trying add new data, or retrieve, dbsets in database context:

system.data.sqlclient.sqlexception: 'a network-related or instance-specific error occurred while establishing connection sql server. server not found or not accessible. verify instance name correct , sql server configured allow remote connections. (provider: sql network interfaces, error: 26 - error locating server/instance specified)'

here's app config data layer project:

    <?xml version="1.0" encoding="utf-8"?> <configuration>   <configsections>     <!-- 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>   <entityframework>     <defaultconnectionfactory type="system.data.entity.infrastructure.localdbconnectionfactory, entityframework">       <parameters>         <parameter value="mssqllocaldb"/>       </parameters>     </defaultconnectionfactory>     <providers>       <provider invariantname="system.data.sqlclient" type="system.data.entity.sqlserver.sqlproviderservices, entityframework.sqlserver"/>     </providers>   </entityframework>   <connectionstrings>     <add name="settingbuilder" connectionstring="data source=(localdb)\projectsv13;initial catalog=settingbuilder;integrated security=sspi;" providername="system.data.sqlclient"/>   </connectionstrings> <startup><supportedruntime version="v4.0" sku=".netframework,version=v4.5.2"/></startup></configuration> 

and have replicated in web.config on web api project:

<?xml version="1.0" encoding="utf-8"?> <configuration>   <configsections>     <section name="entityframework" type="system.data.entity.internal.configfile.entityframeworksection, entityframework, version=6.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" requirepermission="false"/>   </configsections>   <entityframework>     <defaultconnectionfactory type="system.data.entity.infrastructure.localdbconnectionfactory, entityframework">       <parameters>         <parameter value="mssqllocaldb"/>       </parameters>     </defaultconnectionfactory>     <providers>       <provider invariantname="system.data.sqlclient" type="system.data.entity.sqlserver.sqlproviderservices, entityframework.sqlserver"/>     </providers>   </entityframework>   <connectionstrings>     <add name="settingbuilder" connectionstring="data source=(localdb)\projectsv13;initial catalog=settingbuilder;integrated security=sspi;" providername="system.data.sqlclient"/>   </connectionstrings>   <system.webserver>     <handlers>       <add name="aspnetcore" path="*" verb="*" modules="aspnetcoremodule" resourcetype="unspecified"/>     </handlers>     <aspnetcore processpath="%launcher_path%" arguments="%launcher_args%" stdoutlogenabled="false" stdoutlogfile=".\logs\stdout" forwardwindowsauthtoken="false"/>   </system.webserver> </configuration> 

the db exist - when try add-migration or update-database package manager console there no problem , these succeed.

what reason cannot connect db web api project, have no issues doing console?

here structure of db context class:

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.data.entity;  namespace settingbuilder.data {     public class settingbuildercontext : dbcontext     {         public dbset<setting> settings { get; set; }          public settingbuildercontext() //: base("settingbuilder")         {          }          protected override void onmodelcreating(dbmodelbuilder modelbuilder)         {             modelbuilder.entity<setting>().totable("setting");         }     } } 

i following unit of work pattern - spare pasting code here, instantiating unit of work instantiates db context. here's @ controller in web api:

[httppost("[action]")] public void createsetting([frombody]setting setting) {     _unitofwork.settingrepository.createsetting(setting);     _unitofwork.save(); } 

any appreciated.

edit: have made simple console app test this. console app, works - have copied app.config data layer project. however, db has been created in different place qualified name, not 1 specified in app.config (it created settingbuilder.data.settingbuildercontext db)

this leads me assume framework not referencing app config file. there way configure this?

edit 2: works if manually hard code connection string. copied webconfig db context initialisation.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -