1

I'm facing an issue that many already faced, with a difference: neither the SDF file name, or the path, contains invalid characters. I've even tried with the Northwind.sdf file and Ikeep getting the same issue.

And example of a full path: D:\Sviluppo\dotnet\EnergiaClima\EnergiaClimaWindows\App_Data\Northwind.sdf

The error message:

System.ArgumentException: The modelEntityContainerName parameter 'D:\Sviluppo\dotnet\EnergiaClima\EnergiaClimaWindows\App_Data\NorthwindsdfContext' contains characters that are not valid.
   at System.Data.Entity.Design.EntityModelSchemaGenerator..ctor(EntityContainer storeEntityContainer, String namespaceName, String modelEntityContainerName)
   at Microsoft.DbContextPackage.Handlers.ReverseEngineerCodeFirstHandler.ReverseEngineerCodeFirst(Project project)

This issue is driving me crazy: does the EF Power Tools Beta 3 actually works in VS2010? If not, what's the best (and easier) way to get an Entity Model from a SQLCE4.0 DB (something that is not creating a 3.5 DB and editing XML files, if possible)?

I can't understand why SQLCE4.0 support is so poor.

Andrea Sciamanna
  • 1,404
  • 1
  • 15
  • 30

3 Answers3

1

Now it's a verified issue: http://entityframework.codeplex.com/workitem/898

I wonder how the guys test their library: did they ever tried to use EF5 Code First with a SQL CE database?

Anyway, hopefully it will be solved in EF6.

Andrea Sciamanna
  • 1,404
  • 1
  • 15
  • 30
0

Assuming that you would like to create an edmx from a SQL Server Compact file, you can use my SQL Server Compact Toolbox extension to create the edmx from any 3.5 or 4.0 file.

ErikEJ
  • 40,951
  • 5
  • 75
  • 115
  • Why are you assuming I'm using VS2012? I've written "does the EF Power Tools Beta 3 actually works in VS2010". Everything is installed properly, but I keep getting this error message, even though the file name doesn't contain invalid characters. – Andrea Sciamanna Feb 20 '13 at 18:15
  • The Toolbox also Works w. VS 2010 – ErikEJ Feb 21 '13 at 15:17
  • Erik, really, I know that is supposed to work, but it doesn't in my case. As I've written, this happens also with the NorthWind.sdf database. I'm simply looking for help finding a reason why this is happening to me. – Andrea Sciamanna Feb 21 '13 at 18:30
  • OK, let me try to understand: You cannot create a edmx with the Toolbox? What errors do you get? – ErikEJ Feb 21 '13 at 23:46
  • The issue is in my question: when I try to reverse engineer a SQLCE4.0 DB I get that error message I've written above. – Andrea Sciamanna Feb 22 '13 at 07:59
  • Ok, let's recap then. When trying to reverse engineer _any_ SQLCE40 database, I get the error message saying that the file name contains invalid charachters, even if is not true. – Andrea Sciamanna Feb 22 '13 at 15:54
  • So for your first question, regarding the EF Power Tools, maybe you should discuss this bug at entityframewrok.codeplex.com – ErikEJ Feb 22 '13 at 17:05
  • Not sure what I did wrong in this question, but I thought I was quite clear. Anyway, thank you. The right url in case other people need it: http://entityframework.codeplex.com/ – Andrea Sciamanna Feb 22 '13 at 20:32
  • Well, I've posted the bug issue there on Friday (http://entityframework.codeplex.com/workitem/898), but nobody answered yet: at least here you did. By the way, from what I can understand, is not an Entity Framework issue, as I can work without problems with SQLCE4.0. Only the EF Power Tools seems to have issues opening *.sdf files. – Andrea Sciamanna Feb 27 '13 at 07:59
  • I'm having the same problem in VS2012 with EF Power Tools 3 beta. – Adam Tegen Jun 29 '13 at 22:45
  • I'm seeing this problem with VS2012, EF6 and EF Power Tools Beta 4. Was any solution found? – Jammer Feb 18 '14 at 00:27
  • It will be fixed in the EF 6.1 Tools, as you can see here: http://entityframework.codeplex.com/workitem/898 – ErikEJ Feb 18 '14 at 06:05
  • @ErikEJ I've just updated to the latest pre-release of EF alpha 6.1.1 and EF Tools 6.1 and PowerTool beta 4 and I'm still seeing this error. I'm stuck now without this, is there any way around this? – Jammer Feb 21 '14 at 18:38
  • It should be included in 6,1 RTM – ErikEJ Feb 21 '14 at 20:10
0

This is still occurring on existing file based db's. This will occur in both Sql Server Compact and LocalDb. It has to do with the database name under the server instance. If you attempt to connect to a raw .mdf / .sdf directly from the "Reverse Engineer Code First" connection dialogs before connecting to the same db through code, the DB engine will load the database into the server instance with a name that equals the full path of the db because there is no place to name the database (initial catalog) and has to name the database in order to load it to the sql server instance. Then when EF Reverse Engineer Code First attempts to create a context, it chokes on the backslashes (and probably colon) that exist in the DBName. {note: If you connect after you have already issued some code against the database connection string, the server instance loads the database file with the Initial Catalog you provided (which likely doesn't have special characters) and everything is ok.}

The quick and easy solution is to:

1) shut down Visual Studio to kill your connection to the DB.

2) Start SQL Server Management Studio and connect to "(localDB)\v11.0" {note this is for localDB instance, I don't know what the compact DB instance is.

3) Right click on the database name and select rename to rename the database to your desired initial catalog name instead of the full filename path name.

Maybe EF Reverse Engineer Code First tool should evaluate the DBName and only use everything past the last slash minus the file extension for the DBContext? Especially since most of the connection strings define the initial catalog to the same name as the file name.

Hope this helps someone.

Greg Grater
  • 2,001
  • 5
  • 18
  • 24