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

    Pergunta

  • 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

    sábado, 9 de outubro de 2010 01:13

Respostas

  • 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

    domingo, 31 de outubro de 2010 03:55

Todas as Respostas

  • 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

    terça-feira, 12 de outubro de 2010 10:00
  • 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

    quarta-feira, 13 de outubro de 2010 06:19
  • 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
    terça-feira, 26 de outubro de 2010 21:11
  • 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

    domingo, 31 de outubro de 2010 03:55
  • 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

    segunda-feira, 1 de novembro de 2010 16:26
  • Thanks for the note.
    Richard Turner www.bitcrazed.com
    terça-feira, 2 de novembro de 2010 18:30
  • 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

    quarta-feira, 3 de novembro de 2010 20:39