locked
cannot access SQL server 2012 from C# Visual Studio 2013 from laptop with win7 and management studio 2012 RRS feed

  • Question

  • need to access a remote SQL server 2012 (11, X64 bits) from my laptop win7.

    I can access the SQL server and databases on it from Management studio 2012 on my laptop.

    But, I cannot access it from C# VS2012 on my laptop.

    The connect method:

      SqlConnection conn = new SqlConnection(MyConnectString); 
      MyConnectString="Data Source=SQLServerName;Initial Catalog=myDatabase;Persist Security Info=True;User ID=myId;Password=Mypassword"

    I got error:

    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)

    I have tried many solutions that I can find but none of them work for me.

    I used

         sqlcmd -L

    and found that the server name is not in the list. So, how can I make the server accessable from my laptop. "Allow remote connect has been checked" in the server properties. TCP/IP has bee enabled.

    In VS2012 server explorer, we added the server by server name with ID and password that are used to log in from management studio successfully, I got error: 

         Could not reconnect to "SQLServerName", make sure that the machine name and path are valid.

    But, in VS2013, tools --> add database, I can add the server and database and see tables and data without problems.

     It is so weird.

    Any help would be appreciated.


    • Edited by usa2015usa Sunday, November 1, 2015 4:02 PM
    • Moved by Bob Beauchemin Sunday, November 1, 2015 8:18 PM Moving to the forum for client-side SqlClient for best results
    Sunday, November 1, 2015 1:56 AM

All replies

  • Cloud you please check the following

     SQL Server configuration -> client protocols->   TCP/IP protocol should be Enabled

    Sunday, November 1, 2015 6:00 AM
  • Cloud you please check the following

     SQL Server configuration -> client protocols->   TCP/IP protocol should be Enabled

    In SqlServerConfiguration Manager, and in SQL native Client 11.0 Configuration (32 bits), then in Client Protocols, I have set TCP/IP as "Enabled" and the "order" is 3, but I got the same error.

    But, in VS2013, tools --> add database, I can add the server and database and see tables and data without problems. But, it cannot be accessed from C# code.

     It is so weird.

    Any help would be appreciated.




    • Edited by usa2015usa Sunday, November 1, 2015 4:06 PM
    Sunday, November 1, 2015 12:57 PM
  • >>But, in VS2013, tools --> add database, I can add the server and database and see tables and data without problems. But, it cannot be accessed from C# code.

    Is that you mean even in VS2013, you could not access the sql server database from the C# code?


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, November 9, 2015 9:41 AM