5
votes

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
Instead of looking for misterious bugs, make sure the server is running. There's nothing wrong with .NET Core and SQL Server either . Forget about EF Core. Can you connect with SSMS? - Panagiotis Kanavos
@PanagiotisKanavos the server is running, I updated to show I can access via SSMS - Kirsten
Can you connect to it with SSMS? There's nothing wrong with .NET Core, I use it for ETL jobs that do connect to named instances. - Panagiotis Kanavos
BTW which .NET Core version are you using? I've heard that there were some issues with Core 1.0 and old, unsupported Windows versions. 2003 is waaaay too old. Even SQL Server 2008R2 is no longer supported. If you want Express, why don't you install a fresh version? - Panagiotis Kanavos

1 Answers

1
votes

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