1

I was creating a web site project in Visual Studio 2015, created an App_Data folder and tried to add a SQL Server database file.

This error occurred:

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.

I am using Microsoft SQL Server 2014 (v12.0). I checked the connection in SQL Server Configuration Manager, the server connection is enabled, my TCP/IP port is set to 1443, my Firewall is set for the connection as well.

I am able to connect to my server from Visual Studio Tools/Connect to Database Option, it's able to connect either to my server or to a local database. When I test my connection from there, it works.

I also see the connection is enabled and running from server explorer, and when I drag and drop an SQL DataSource Wizard from my ToolBox to an aspx page, the wizard sees the database and is ready to import it as well.

I also have tried double checking the connection under services.msc from cmd and it's all up and running.

Yet, when I want to right click and add a SQL Server database file to my App_Data folder, this error comes up.

I have no idea what is wrong.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • What is the server name you are providing when you trying to connect? – krish Jun 15 '16 at 18:07
  • To be able to use these "free-floating" `.mdf` database file, you **must have** SQL Server **Express** (or LocalDB = Express for devs) installed. Any other edition *will NOT work*. Do you have Express or LocalDB installed and ready to use? – marc_s Jun 15 '16 at 18:24
  • Yes, I do have SQLEXPRESS and have my LocalDB configured. – Alexander Phoenix Jun 15 '16 at 19:16
  • krish, the server I'm trying to use is my LocalDB, I have Connected Visual Studio with it. – Alexander Phoenix Jun 15 '16 at 19:17

2 Answers2

0

Try to use (localdb)\mssqllocaldb as server name to connect to the LocalDB automatic instance. for more information read this article: http://www.sqlcoffee.com/SQLServer2014_0010.htm

Jason Clark
  • 1,307
  • 6
  • 26
  • 51
0

Just for documentation (and SQL Express users having the same problems)

1. Check that SQL Express (master-) database exists and is reachable

In Server Explorer => Data Connections => Add Connection

  • (LocalDb)\mssqllocaldb
  • (LocalDb)\v12.0
  • (LocalDb)\v11.0

For further SQL Express problems see: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance

2. Configure Default Connection in Visual Studio

If you upgraded SQL Express the wrong connection string still resides in the VS configuration

Tools => Options => Databas Tools => Data Connections -> "(LocalDB)\mssqllocaldb"

Fried
  • 1,323
  • 12
  • 21