.Net Core 2.0 with EF7 connecting to SQL Server Express. Error: 26 - Error Locating Server/Instance

.net-core entity-framework-core

Question

I am trying to connect to an 2008R2 SQLEXPRESS instance that is running on a 2003 server.

I can connect to the database from within my .net core 2.0 project using Server Explorer

I can run programs written in .net framework that connect to the database.

However when I try to connect from within my .net core project I get the following error

System.Data.SqlClient.SqlException (0x80131904): 
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: 26 - Error Locating Server/Instance Specified)
at System.Data.SqlClient.SqlInternalConnectionTds. etc

The problem is not the format of the connection string because it works on a local back up of the database.

The connection string is in appsettings.json similar to

"ConnectionStrings": {
"MyDatabase": "Server=MySERVER\\SQLEXPRESS;Database=mydatabase;Trusted_Connection=False;User=sa;password=mypassword"

SQL Server Browser is started . I can access the data via Management Studio

I am not running SQL Server Agent. When I try and start it I see in the event logger

SQLServerAgent could not be started (reason: This installation of SQL Server 
Agent is disabled.  The edition of SQL Server that installed this service
does not support SQL Server Agent.).
1
5
4/20/2018 11:50:12 AM

Popular Answer

I have been able to work around by using the port number in the connection string instead of the instance name.

As advised here

And to find the port I can use

USE master
GO
xp_readerrorlog 0, 1, N'Server is listening on' 
GO
1
5/28/2018 9:30:20 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow