开发者

Does the Entity Framework use a default intital catalog and what assumptions does it make?

I did (pretty much) everything correct in a new EF project, but I forgot to use the named connection string in the EF context class, so, it used the default.

It created a new database inside the SQL Express default data directory, and it wor开发者_高级运维ked perfectly.

When I realised my mistake (After wondering for ages why no files were showing up in the app_data folder), I renamed the class to use the named connection string and then I kept getting the following error:

Unable to complete operation. The supplied SqlConnection does not specify an initial catalog.

I know how to fix this, but, EF is like magic to me! I can't believe it works as well as it does and I am just curious as to what it uses by default / is there a list anywhere of "assumptions" that EF uses on your behalf if you specify nothing?


By default it uses database with the same name as your context but once you specify custom named connection string you must provide the name of used database either by Initial Catalog or Database parameter.


I had the same problem but I figured it out by changing the web.conf. You need to specify an initial catalog and Integrated security and make a user instance.

Here is working web.conf:

add name="MovieDBContext"
   connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Movies.mdf;Initial Catalog=Movies;Integrated Security=SSPI;User Instance=true"
   providerName="System.Data.SqlClient"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜