5

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.).
Kirsten
  • 15,730
  • 41
  • 179
  • 318
  • investigating https://github.com/dotnet/corefx/issues/24175 – Kirsten Apr 20 '18 at 11:17
  • 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 Apr 20 '18 at 11:37
  • @PanagiotisKanavos the server is running, I updated to show I can access via SSMS – Kirsten Apr 20 '18 at 11:39
  • 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 Apr 20 '18 at 11:40
  • 1
    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 Apr 20 '18 at 11:42
  • The reason you can't connect to a Win 2003 machine could well be that SMB v1 isn't enabled on the domain or computer for obvious security reasons. – Panagiotis Kanavos Apr 20 '18 at 11:43
  • I updated the question to show I am using 2.0 I am not using SMB – Kirsten Apr 20 '18 at 11:43
  • You *are* using SMB. That's the networking protocol used by Windows. `MySERVER\\SQLEXPRESS` isn't a tcp name either which means you are using named pipes to connect. *Maybe* you could replace the name with the IP address or the fully qualified name. Why are you using such an obsolete Windows version though? You could easily install Express on your own machine - in fact Visual Studio can install it – Panagiotis Kanavos Apr 20 '18 at 11:45
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/169437/discussion-between-kirsten-g-and-panagiotis-kanavos). – Kirsten Apr 20 '18 at 11:47

1 Answers1

1

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
Kirsten
  • 15,730
  • 41
  • 179
  • 318