locked
System.InvalidOperationException while accessing DB in EF: The context cannot be used while the model is being created. RRS feed

  • Question

  • User-706835752 posted

    We are building a Web App using ASP.NET MVC  our sign-in feature requires Azure AD, so we used some of the GitHub Samples published by Microsoft on how to store/cache tokens. everything works when I am running locally as localhost. But when we published the web app to Azure the Sign-in feature is broken, and further debugging states it because of below mentioned exception.

     

    The culprit line of code is

     

                // look up the entry in the DB

                Cache = db.UserTokenCacheList.FirstOrDefault(c => c.webUserUniqueId == User);

     

    The authenitcationcontext class and TokenCache is same as here

     

    I looked at the internet, there were couple of suggestions, but till now all is in vain. Any help highly appreciated.

     

    Thanks in advance

    Tuesday, June 2, 2015 2:40 PM

All replies

  • User-1926401737 posted

    Hi Ashirs,

    System.InvalidOperationException while accessing DB in EF: The context cannot be used while the m...

    This thread discussed a similar issue, you could refer to it.

    Wednesday, June 3, 2015 4:53 AM
  • User1534684113 posted

    System.InvalidOperationException while accessing DB in EF: The context cannot be used while the m..

    .

    Thanks for your post.
    As per this case, Can you make sure you have changed "parameter value" in "O365-WebApp-SingleTenant/Web.config" like below:

    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">  
      <parameters>
        <parameter value="Data Source=dbserver;Initial Catalog=database;User ID=xxx;Password=xxx;" />  
      </parameters>
    </defaultConnectionFactory>

    Further any exceptions, kindly let us know.

    Thursday, June 11, 2015 11:08 PM