Connecting String Tips with EF5 and localdb

Connection String Reference from Class Constructor

When specifying a connection string property use the ‘name’ key word within contructure which instructs EF5 to throw an exception if it doesn’t find it. I would say this is better practice than not specifying the key word ‘name’.

public class ApplicationDB:DbContext



: base(“name=EF5.Demo)



Specifying a Connection Factory

You tell EF5 your using localdb by specifying it within your config file.


<defaultConnectionFactorytype=System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework>


<parametervalue=v11.0 />




Specifying a Connection string

AttachDbFileName should only be used during development.

DataDirectory is useful during development as it more eaily allows a team of developers to work on the one code base.


<addname=EF5.DemoproviderName=System.Data.SqlClientconnectionString=Data Source=(LocalDB)v11.0;AttachDbFileName=|DataDirectory|EF5.Demo.mdf;Integrated Security=True;MultipleActiveResultSets=True />


I’ll also refer you to this useful post: