Question

I was getting the below error when trying to connect to my SQLEXPRESS database using the Generate Database wizard of EF.

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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

I enabled the TCp/IP for SQLEXPRESS as per the below question.

Enable remote connections for SQL Server Express 2012

I just enabled the tcp/Ip settings(did'nt change the IP2 and all) and restarted the sql server process.

After restarting the service my server is not being detected in connection properties dialog window.

Why is this happening? What should I do now?

Was it helpful?

Solution

I just ran into this one trying to set up an EF connection late at night. It turned out I wasn't reading the connection settings correctly. I was putting JUST the server computer name in the 'Server Name' box and was putting the instance name in the 'Database' box.

'Server Name' should be (COMPUTERNAME)\(INSTANCE) and Database should be the actual database name.

Hope this solves your problem!

OTHER TIPS

I would first try creating an Entity Data Model (.edmx file) from an existing database and then create an new (empty) database within VS2013 using Server Explorer if you haven't already. Then use the Data Entity Model Wizard to create new tables/schema from a working database to your empty database using migrations. If this doesn't work then you know your problem probably exists with your SQL Express Instance and not how you configured your connection strings for this project.

I tried these steps in an MVC 4 project in VS2013 and had no problem so maybe you can try also:

STEP 1: Create Date Entity Model from existing db. Right-click Solution Name -> Add New Item -> ADO.NET Entity Data Model Note: Uncheck save connection string because we just want the sample ADO.NET Model when using existing database

STEP 2: Create new Database from Server Explorer -> Data Connections -> Create New SQL Server Database (test connection)

STEP 3: Right-click on model in .edmx diagram and select Generate Database from Model...

STEP 4: Enable-Migrations, Add-Migration MigrationName, update-database from NuGet Console Manager.

NOTE: You will have two connection strings if you plan on using Authentication out-of-the-box. I also installed EF 6.0 from NuGet.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top