views:

54

answers:

2

I'm migrating an application from LINQ-to-SQL to Entity Framework and have changed the line:

using (var db = new MainDataContext(SystemHelpers.GetDatabaseConnectionString()))

to

using (var db = new MainDataEntities(SystemHelpers.GetDatabaseConnectionString()))

where SystemHelpers.GetDatabaseConnectionString()) is a file path to an .mdf file.

It works in LINQ-to-SQL but in Entity Framework the above line gives me this error:

The format of the initialization string conflicts with the specification which begins with '0';

which is the best translation I can do from the German:

"Das Format der Initialisierungszeichenfolge stimmt nicht mit der Spezifikation überein, die bei Index '0' beginnt."

+2  A: 

Entity Framework connections string are more complicated than standard connection strings.

They are made up of three parts:

  1. the Provider Connection String => this is what you're providing
  2. the Metadata => which is where the EF should get the CSDL, MSL and SSDL from (i.e. Conceptual Model, Mapping and Storage Model)
  3. the Provider name => i.e. for SQL server this is generally System.Data.SqlClient

Here is what it one might look like:

metadata=res:///Model.csdl|res:///Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;Initial Catalog=Database;Integrated Security=True;Pooling=False;MultipleActiveResultSets=True"

Hope this helps

Alex

Alex James
+1  A: 

EF connection strings can't be the DB connection string alone. They contain the DB connection string, but they have much more information, too. It sounds like you're trying to use the DB connection string alone. That won't work. See this example for how to build an EF connection string.

Craig Stuntz