Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.

Answered Error - "File already exists. Try using a different database name."

  • Saturday, October 09, 2010 1:13 AM
     
     

    I've been using CTP4 with CE4 since some time, without any issues with Create, Recreate, Always options to create SDF database. This week I upgraded to MVC 3 Beta, WebMatrix etc using WPI. Since then, I keep getting error "File already exists. Try using a different database name."

    Now this not only occurs after compilation, with or without model change, with any option. Say I select not to create DB if it exists, yet I get the error. Timestamp on file keeps changing too...

    When error comes - hitting refresh always gets past the issue. Be it debug or release config. I haven't had a chance to investigate deeper, but I did discover others asking:
    http://stackoverflow.com/questions/3882963/why-is-ef4-trying-to-re-create-my-database-even-though-the-model-hasnt-changed

    Any known issue?

    Thanks
    --Sharad

All Replies

  • Tuesday, October 12, 2010 10:00 AM
     
     

    I have same problem, but I use RecreateDatabaseIfModelChanges method. Did you solve your problem and how?

    I saw that problem was in SQL CE 4.0 version. For me CTP 2 or the one, which is included in WebMatrix Beta 2 or maybe also in ASP .NET MVC 3 beta, isn't working properly. Right version is CTP 1, which is founded on Microsoft download site.

    Ziga

  • Wednesday, October 13, 2010 6:19 AM
    Moderator
     
     

    Hi,

    Thank you for bringing this to our attention, we will investigate what is causing the issue with CTP2 of SQL CE 4.0, in the meantime it sounds like re-installing CTP1 is the way to go; http://www.microsoft.com/downloads/details.aspx?FamilyID=0D2357EA-324F-46FD-88FC-7364C80E4FDB

    ~Rowan

  • Tuesday, October 26, 2010 9:11 PM
     
     

    Rowan - did you get anywhere with this investigation? I've just hit the same issue when playing with EF, SQLCE & code-first.

    Was planning on embarking on a full-blown project using the above tech and really need to know if there's a fix in the pipeline for this issue.

    Thanks in advance.


    Rich Turner
  • Sunday, October 31, 2010 3:55 AM
    Moderator
     
     Answered

    Hi,

    Yes, this turns out to be a bug in SQL Compact CTP2 when using the |DataDirectory| macro in a connection string (which DbContext does by default). There are two options to work around the issue;

    1) Remove CTP2 and move back to CTP1 of the SQL Compact provider

    2) Specify a full connection string that doesn't use the |DataDirectory| macro, the easiest way to do this is pass "Data Source=<filename>" to the DbContext constructor that accept a string.

    The SQL Compact team is aware of the issue and working on a fix.

    ~Rowan

  • Monday, November 01, 2010 4:26 PM
     
      Has Code

    Wow, Rowan, what a timley answer.  I am struggling with this the next morning.

    I have added the string param to the base class now it is complaining that Data.Entity.CTP does not have ...

     

    	public class BondDB : DbContext
    {
    public BondDB() : base("Data Source=/App_Data/BondDB.sdf") { }
    Error 1 The type 'System.Data.Objects.ObjectContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. E:\Source\DotNet4\TPS\Mvc3\MVC3_EF4_CodeFirst_Razor\MvcApplication4\Models\BondDB.cs 12 10 MvcApplication4

    I shouldn't have to refrence System.Data.Entity if I am referencing Entity.CTP should I ?


     

    Thanks, Terrence

  • Tuesday, November 02, 2010 6:30 PM
     
     
    Thanks for the note.
    Richard Turner www.bitcrazed.com
  • Wednesday, November 03, 2010 8:39 PM
    Moderator
     
     

    Hi Terrence,

    Yes in some cases you will have to reference System.Data.Entity because CTP4 exposes types from this assembly in its API surface (a side effect of CTP4 building on top of the existing components.

    BTW I noticed you are using "Data Source=/App_Data/BondDB.sdf" as the connection string, you will need to replace App_Data with the full path to successfully work around the issue. (The bug is a result of the SQL Compact provider not correctly replacing App_Data in some cases).

    ~Rowan