I just started learning EF (not core) and was creating my first code-first application. This is a C# console application where all I am doing is adding a migration and then simply creating the sample database (same name as my solution). As I try to run Update-Database
, I get this error:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.)
Steps I searched and implemented and have still not been able to resolve this are:
My connection string is:
<add name="ConsoleDBContext"
connectionString="Data Source=(LocalDb)\SQLEXPRESS;Initial Catalog=CodeFirst_Demo;Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
Also tried removing "localDB" but no avail.
The steps followed in the C# code using Package Manager Console are:
I would be extremely grateful for any help in this regard.
Thanks everyone! My issue got resolved by explicitly entering the startup project name("CodeFirst_Demo" in my case) along the "Update-Database" command . Like the below :
update-database -StartupProjectName CodeFirst_Demo