Reputation: 3443
I am learning ASP.NET MVC, from official site.
When I reach at this tutorial page, after creating Movies controller, when I navigate to url: localhost://xxxx/movies/index I got an exception.
Exception Message is :
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
My system details are:-
Connection string in web.config file is this
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename="|DataDirectory|\aspnet-world movies-20150825083408.mdf";Initial Catalog="aspnet-world movies-20150825083408";Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="MovieDBContext" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
The exception is in this action method at line #20
public ActionResult Index()
Line 19: {
Line 20: return View(db.Movies.ToList());
Line 21: }
Upvotes: 0
Views: 1029
Reputation: 1964
it think the issue is with connection string.
when the tutorial was created it was using SQL server 2012 localDB then connection string was "Data Source=(LocalDB)\v11.0;"
but in VS 2015 SQL server 2014 it is changed to "(localdb)\ProjectsV12;"
Update: Microsoft again changed the localDb name in VS 2015
Use "(LocalDB)\MSSQLLocalDB;"
so try to change connection string to
"(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Movies.mdf"
and try running. good luck
you can find the working code hear : GettingStartedWithASPNETMVC5
Upvotes: 1