Entity Framework 4.1 Code First persist error RRS feed

  • Question

  • Hello,

    I've created a simple project to study the new features of Entity Framework 4.1 Code First mainly the automatic database creation.

    When the application is performed, if  the database doesn't exists, the entity Framewrok creates new one. After that, the application try to create an new entity and try to persist on the database using SaveChanges() method. At this moment, some times I get the message:

    Cannot open database "database_name" requested by the login. The login failed. Login failed for user 'domain_name\user_name'

    I've changed the code to wait four seconds after creation of database using the following line:


    System.Threading.Thread.Sleep(new TimeSpan(0, 0, 0, 4))



    after that, the new entity was stored on database! Why ?!

    What can be wrong? Can't I create a new entity and call SaveChanges immediatly after database creation ?




    Tuesday, September 13, 2011 2:09 PM

All replies

  • Hi Marcos,


    According to your description, I haven't met such question yet, Would you please feel freel to show your code here or ping me: ALAN

    Have a nice day.

    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Sunday, September 18, 2011 10:02 AM