c# - web.config connection string not set Context? -


i using asp.net mvc , using entity framework in class library.

my entity context:

public class amarcontext : dbcontext {     public amarcontext()         : base("amargirientities")     {      }      public dbset<amartable> amars { get; set; }     public dbset<guiddetailstable> guiddetails { get; set; }     public dbset<guididtable> guidids { get; set; }     public dbset<ipstable> ips { get; set; } } 

my web.config connectionstring:

    <configuration>   <connectionstrings>     <add name="amargirientities" connectionstring="data source=localhost;integrated security=false;initial catalog=framesoftamar;user id=username;password=pass;connect timeout=15;encrypt=false;packet size=4096" />   </connectionstrings>   <configsections>      <sectiongroup name="system.web.webpages.razor" type="system.web.webpages.razor.configuration.razorwebsectiongroup, system.web.webpages.razor, version=2.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35">       <section name="host" type="system.web.webpages.razor.configuration.hostsection, system.web.webpages.razor, version=2.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" requirepermission="false" />       <section name="pages" type="system.web.webpages.razor.configuration.razorpagessection, system.web.webpages.razor, version=2.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35" requirepermission="false" />     </sectiongroup>   </configsections>    <system.web.webpages.razor>    ... 

but if check connection string return me this:

data source=(localdb)\mssqllocaldb;attachdbfilename=|datadirectory|amargirientities.mdf;initial catalog=amargirientities;integrated security=true;multipleactiveresultsets=true 

why? if test class library in console application , set connection string in app.config works.but asp.net mvc not working.

do tried add <clear/> tag stefan comment? should solve.

check section too:

<entityframework> <defaultconnectionfactory type="system.data.entity.infrastructure.sqlconnectionfactory, entityframework"> <parameters> <parameter value="data source=(localdb)\v11.0...." multipleactiveresultsets=true" /> </parameters> </defaultconnectionfactory> </entityframework>

if not solve, check located web.config file. remember there precedence convention on file.

see: asp.net configuration file hierarchy , inheritance


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -