Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 worked 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?

like image 782
Wil Avatar asked Dec 28 '25 16:12

Wil


1 Answers

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.

like image 147
Ladislav Mrnka Avatar answered Dec 31 '25 08:12

Ladislav Mrnka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!