none
Cannot create SqlServerCe4.0 file (.sdf) with EF code first RRS feed

  • Question

  • Hi,

    I thought this was all working in my project (WPF desktop application) but now I simply cannot get EF to create a database file for me! It will open existing files. I have checked that the application can create files in the working folder (OK). I have tried EF4.1, EF4.2, private SqlServerCe4.0 deployment, centrally installed SqlServerCe4.0. I have set the Database initialisation strategy to "CreateIfNotExists". Conection strings, provider name all seem OK (I can open existing files). I have come to a dead end investigating this. Can anyone make some suggestion of how to find out what is wrong please?


    ChangedDaily
    Sunday, December 25, 2011 7:16 PM

All replies

  • Hi ChangedDaily,

    Welcome!

    You can try to set initialization strategy:

    Database.SetInitializer<DbContext>(    new DropCreateDatabaseIfModelChanges<DbContext>());
    
    

    You can refer here for the detail information: http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-code-first-walkthrough.aspx

    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.

    Monday, December 26, 2011 8:25 AM
    Moderator
  • Hi,

     

    Thanks for the idea but I have already tried all the initialisation strategies.

    I believe I have now eventually found the problem. It seems to be to do with setting the initialisation strategy using the static Database.SetInitializer<>... and changing the connection string later down the line. By using DbContext.Database.Create() I have been able to get things going again and I think my code has got better along the way. I'm still not quite sure why things appeared to just stop working but I expect that will become clear as well.

     

    Thanks


    ChangedDaily
    Monday, December 26, 2011 5:49 PM
  • Hi ChangedDaily,

    Thanks for your feedback.

    Your post makes me confuse now, I think I am not very sure about your question.  Would you please share your code or demo a project and ping me here: v-alache@microsoft.com

    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.

    Tuesday, December 27, 2011 2:48 PM
    Moderator