1

I can't get a connection between C# and SQL Server.

I have two Windows servers (1 with SQL Server, 1 with the application).

I get this error:

System.Data.Entity.Core.EntityException: The underlying provider failed on Open

System.Data.SqlClient.SqlException:
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)

I think there is something wrong with my connection string...

The setup worked on localhost with 0 problems.

I have a 1:1 copy of the SQL Server database on my server.

I have a two Windows server setup. I already opened the inbound rules port 1433 on the ms sql server and opened the outbound port 1433 for application server. I added the user in SQL Server and tried different connection strings. I don't know what's wrong.

Please help best regards

<connectionStrings>
    <add name="XXX_DATA_DEVEntities4" 
         connectionString="metadata=res://*/Entities.csdl|res://*/Entities.ssdl|res://*/Entities.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=XX.XXX.XXX.XXX\Servername\MSSQL2017STD;initial catalog=XXX_DATA_DEV; Persist Security Info=False;User ID=usernam;Password=password;multipleactiveresultsets=True;application name=EntityFramework&quot;" 
         providerName="System.Data.EntityClient" />
</connectionStrings>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • "Data Source" looks strange, it should be either in the form of either "data source=server" or "data source=server\instance" imho – Alexander Powolozki Aug 15 '19 at 11:53
  • Yes I think there is the problem, so what it has to look like, I also tried this way: data source=servername\MSSQL2017STD; also didn't work. I ithink he can't connect without ip address, am I right? – theCryptoGuy388 Aug 15 '19 at 11:56
  • It depends on your network and server configuration. can you connect to the server from your workstation with sql server management studio? Additionally you can check if tcp/ip protocol on the server configuration is enabled – Alexander Powolozki Aug 15 '19 at 12:04
  • yes tcp/ip is activated. No I can't establish a connection because I dont't know what I need to put in the field servername in sql server management studio. Do I need to put servername/MSSQL2017STD or do I need to put IP-address in it? – theCryptoGuy388 Aug 15 '19 at 12:10
  • it should be the same as data source – Alexander Powolozki Aug 15 '19 at 12:13
  • Check sql server configuration settings->protocols for that instance - if names pipes and TCP/IP are disabled, or Sql server browser service is not running - you'll get that error. – Vytautas Plečkaitis Aug 15 '19 at 12:27
  • can you ping the server? – Eray Balkanli Aug 15 '19 at 13:34
  • @theCryptoGuy388 have you tried adding an inbound rule for the port on the sql server machine (port 1433) under firewall setting? https://consignor.zendesk.com/hc/en-us/articles/115000647774-Opening-Windows-Firewall-for-client-connections-to-server – Wamiq Rehman Aug 15 '19 at 13:34
  • `XX.XXX.XXX.XXX\Servername\MSSQL2017STD` doesn't look like a valid data source. You would use the IP *or* the server name, not both. Do you have a named instance installed on that server? –  Aug 15 '19 at 13:38
  • Here is a good trouble shooting answer to a similar question: [Why am I getting “Cannot Connect to Server - A network-related or instance-specific error”?](https://stackoverflow.com/a/18060818/1260204) – Igor Aug 15 '19 at 14:18
  • I hope, this [answer](https://stackoverflow.com/a/57510191/6598234) with another similar question would help you.. – Shekar Kola Aug 15 '19 at 19:23
  • I tried everything you posted, I dont get this problem solved. I can't ping to this server tcp-port 1433 is open and udp port 1434 also. Also Telnet dont get a connection. Don't know what can I do now... How can I find the problem? – theCryptoGuy388 Aug 16 '19 at 12:34
  • @theCryptoGuy388 How these two server are connected with each other ? – Wamiq Rehman Aug 16 '19 at 18:08
  • @WamiqRehman at the moment the two servers are not connected. Do I need to connect them over vpn tunnel? – theCryptoGuy388 Aug 18 '19 at 11:14

0 Answers0