0

I'm getting the below error while trying to connect and get the data to Visual webpart (VS 2013) from SQL Server 2016:

An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

Additional information: 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

Approaches that I tried :

  1. I'm able to add connection successfully in server explorer (VS2013).

  2. Tried binding the grid view with the SQL data getting this error:

    enter image description here

  3. I'm able connect to the SQL Server 2016 with Management Studio 2012 with same account

  4. I tried by restarting services and enabling TCP/IP stopping the firewall in SQL Server nothing fixed, checked SQL connection properties in Management Studio allow remote connections option is also checked

connection in server explorer vs2013: enter image description here

code:enter image description here Please help

karthik
  • 101
  • 3
  • Possible duplicate of [Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"?](https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci) – Panagiotis Kanavos Aug 03 '18 at 13:42
  • Which means the connection string on the *web server* is wrong, or there's something wrong with the network. – Panagiotis Kanavos Aug 03 '18 at 13:43
  • I've already tried all the things that mentioned in that post – karthik Aug 03 '18 at 13:44
  • The call stack shows that the error is thrown in the `gridviewbind() method. What is the connection string used there? Did you try debugging your code? – Panagiotis Kanavos Aug 03 '18 at 13:45
  • i tried in by using LINQ to SQL(able to add server connections in vs2013) while execution it is getting failed and tried ADO.NET entity model – karthik Aug 03 '18 at 13:46
  • 1
    Tried *what*? If the connection string is wrong, nothing else is going to fix it. At the very least post the code. Or debug the application and *check* the connection string. Is it the correct one? Perhaps you are using a computer name when a fully-qualified name is required? Can you connect using an IP? If yes, there's a DNS problem (or wrong server name of course) – Panagiotis Kanavos Aug 03 '18 at 13:46
  • Please don't describe what you tried. Show the code in the question itself. Trying different APIs won't fix a bad connection string. – Panagiotis Kanavos Aug 03 '18 at 13:47
  • check the connection string screenshot – karthik Aug 03 '18 at 13:57
  • I can't check whether you have a machine called `SQLservername` in your network. Do you? *Did you try with the IP instead of the machine name ?* – Panagiotis Kanavos Aug 03 '18 at 13:59
  • tried with IP address too, just tried with alias name it's working now thank you for your help – karthik Aug 03 '18 at 14:05

0 Answers0