0

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:-

  • Windows 10 pro (64 bit)
  • Visual studio for community 2015
  • SQL Server 2014 (64 bit)

Connection string in web.config file is this

<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=&quot;|DataDirectory|\aspnet-world movies-20150825083408.mdf&quot;;Initial Catalog=&quot;aspnet-world movies-20150825083408&quot;;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:         }
2
  • Please show the code relating to your SQL connection string from the web config, removing all credentials info obviously. Commented Aug 25, 2015 at 18:32
  • 1
    Did you complete step 5? Commented Aug 25, 2015 at 18:34

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

hey Jophy job thanks for reply i tried to change the connection string as you suggest but following exception has been caught. Keyword not supported: '(localdb)\projectsv12;attachdbfilename'.
the problem is at this action method: public ActionResult Index() { return View(db.Movies.ToList()); }
Sorry Microsoft again changed the localDB database Name . please use "Data Source=(LocalDB)\MSSQLLocalDB"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.