Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.).
like image 482
Kirsten Avatar asked Nov 08 '22 08:11

Kirsten


1 Answers

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
like image 96
Kirsten Avatar answered Dec 14 '22 23:12

Kirsten