3

I'm following [this tutorial], I'm trying to create EF database in C# console application, but (even if I do exactly everything as in tutorial) it fails on

db.Blogs.Add(blog);
db.SaveChanges();

lines. Error:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.dll. Additional information: 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: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)

As author of tutorial says, it shouldn't require me to do anything to configure my DB, but it seems like it does.

What should I do to make it work?

Software that I use: Visual Studio 2015, EntityFramework 6.1.3.

Piotrek
  • 10,919
  • 18
  • 73
  • 136

2 Answers2

1

In Visual Studio 2015 the built in SQL database the comes with it is mssqllocaldb and not SQL Express.

This can be accessed with:

(localdb)\MSSQLLocalDB

rather than

.\sqlexpress

In the tutorial under the section after "You can connect to this database using Server Explorer in Visual Studio" follow the instructions to connect to a database and replace .\sqlexpress with (localdb)\MSSQLocalDB if you can connect this database then change your connection string in your application.

oceanexplorer
  • 1,209
  • 3
  • 11
  • 24
-1

The solution that worked for me is:

  1. Open Visual Studio installer (*.exe file used to install Visual Studio)
  2. Click on "Modify" button
  3. Find "Microsoft SQL Server Data Tools" and check it
  4. Click "Update"

Now your database should work.

Piotrek
  • 10,919
  • 18
  • 73
  • 136