Microsoft Entity Framework Connection String

I was recently creating a Windows Azure app and used the Microsoft Entity Framework. If you have used LINQ to SQL or the SQL Client in ADO.NET before then you will be use to setting a connection string in your web.config file. The Entity Framework has a connection string also, but it is different from what LINQ to SQL or the SQL Client uses. This is important to keep in mind when you are creating your data access logic in a separate project that compiles into a separate assembly. You will obviously have to reference your assembly containing the Entity Framework data access components in your main project, but you will also have to bring over the connection string. This might be important to know if you are ever configuring an application at a customer site and are not copying a Entity Framework connection string directly from your dev machine’s web.config file. Below is a sample Entity Framework connection string.

metadata=res://*/[EntityModelName].csdl|res://*/[EntityModelName].ssdl|res://*/[EntityModelName]\.msl;provider=System.Data.SqlClient;provider connection string=”[SQL CONNECTION STRING GOES HERE]”

Notice the connection string references three embedded resource files with a .csdl, .ssdl and .msl file extension. These different files are required and by default are compiled into the assembly as resource files. Replace the [EntityModelName] with the name of the model you created in your Visual Studio project. The very last part of the Entity Framework connection string is the actual SQL connection string.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s