none
vb.net cannot connect to mssql server

    Question

  • I am trying to connect to ms sql server but I get 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)

    This is in Windows form application. This application works correct and connects to MSSQL Server in other all other PCs but not in mine. This server is in local network. So I guess problem is not in MSSQL Server.

    Before 2 months this application worked on my PC as well, as I coded it with visual studio 2008 and was debugging, all worked great. After that I have installed Visual studio 2012 and MSSQL express 2005 and 2008. So these changes have been made on my PC. Now I go back to edit my application and it cannot connect anymore.

    I have searched the web and found that these servers 2005 and 2008 could be the problem. I have removed them both from my PC. Now I have Visual studio 2008 and Visual studio 2012. Could it be the problem for my connection to SQL server? There is no problem with connection to oracle or My SQL.

    I cannot remove Visual Studio 2012 as I have code with it. Please help.

    Monday, December 23, 2013 12:05 PM

Answers

All replies

  • maybe some reference changed or dlls. I dont know. 
    Monday, December 23, 2013 12:07 PM
  • This is in Windows form application. This application works correct and connects to MSSQL Server in other all other PCs but not in mine.

    Verify the SQL Server Service is running and that the connection string is correct, with the Data Source specifying a running local instance of SQL Server.  Since you have multiple instances of SQL Server installed, you will need to append the instance name to the host name to connect to a non-default instance. 

    Use the SQL Server Configuration Manager to see the list of installed SQL Server services and status.  The name of the listed SQL Server database engine services will be in the format "SQL Server (instance-name)".  The Data Source in your connection string should be in the format "host-name\instance-name" (e,g. "MYPC\SQLEXPRESS").


    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

    Monday, December 23, 2013 1:02 PM
  • Verify the SQL Server Service is running and that the connection string is correct.

    So I assume all this is working as other machines can connect to that server and get data from database. So problem is mine PC. Correct?


    Monday, December 23, 2013 1:53 PM
  • Verify the SQL Server Service is running and that the connection string is correct.

    So I assume all this is working as other machines can connect to that server and get data from database. So problem is mine PC. Correct?


    If you are connecting to a remote instance and other clients can connect to same, then the instance must be started.  But you mentioned local instances of SQL 2005 and 2008 Express edition.  My suggestion applies if you are attempting a local connection.

    For the remote connection, us your connection string identical to the other clients that are working?


    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

    Monday, December 23, 2013 2:20 PM
  • Could be a number of things in the network portion. Perhaps this client is attempting a named pipes connection and the other successful connections are using TCP? You will have to troubleshoot starting with the IP address, then name resolution, protocol, port number, etc. See this topic in the SQL Server TechNet Wiki How to Troubleshoot Connecting to the SQL Server Database Engine

    Rick Byham, Microsoft, SQL Server Books Online, Implies no warranty

    Monday, December 23, 2013 4:42 PM
    Answerer
  • First, make sure that server name is correct.
    http://sqlserver-help.com/2011/06/19/help-whats-my-sql-server-name/

    Balmukund Lakhani | Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
    --------------------------------------------------------------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------------------------------------------------------------------
    My Blog | Team Blog | @Twitter
    Author: SQL Server 2012 AlwaysOn - Paperback, Kindle

    Tuesday, December 24, 2013 7:47 AM
    Moderator
  • Hi,

    This is general connection error which indicates that SQL Server cannot be found. I would suggest you to take the following methods to troubleshoot the issue.
    1. Check if you are able to ping SQL Server.
    2. If you had installed SQL Server Management Studio on your PC, please check whether you can connect to the SQL Server instance via SQL Server Management Studio.
    3. If possible, post the connection string here.

    Thanks.


    Tracy Cai
    TechNet Community Support

    Wednesday, December 25, 2013 3:25 AM
    Moderator
  • Thanks for all replays.

    I checked on server service is running. SQL Server (MSSQLSERVER). Hostname is ds.

    Yes, I can ping to server.

    Yes, connection string identical to other PCs.

    No, I cannot connect to server via sql management studio. Connection string: 

    connetionString = "Data Source=ds;Initial Catalog=ctl;User ID=user;Password=passw"

    ---------------------------
    Microsoft Visual Studio
    ---------------------------
    Could not load file or assembly 'Microsoft.SqlServer.Management.Sdk.Sfc, Version=10.0.0.0, Culture=neutral, PublicKeyToken=8984...' or one of its dependencies. The system cannot find the file specified.

    This is what I get:

    A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
    System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled exception</Description><AppDomain>OPS-3.vshost.exe</AppDomain><Exception><ExceptionType>System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5...</ExceptionType><Message>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)</Message><StackTrace>   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
       at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject)
       at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
       at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
       at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
       at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
       at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
       at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
       at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
       at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
       at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
       at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
       at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
       at System.Data.SqlClient.SqlConnection.Open()



    • Edited by Innspiron Friday, December 27, 2013 12:00 PM
    Friday, December 27, 2013 11:57 AM
  • Is there a firewall runing on your client? Then you have to unblock the port used by SQL Server, otherwise the firewall will block all connections to SQL Server.

    See Configure the Windows Firewall to Allow SQL Server Access


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Friday, December 27, 2013 12:24 PM
    Moderator
  • Tested when firewall turned off. Same problem.
    Friday, December 27, 2013 12:44 PM
  • Can you please try http://support.microsoft.com/kb/914277

    Balmukund Lakhani | Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
    --------------------------------------------------------------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------------------------------------------------------------------
    My Blog | Team Blog | @Twitter
    Author: SQL Server 2012 AlwaysOn - Paperback, Kindle

    Friday, December 27, 2013 1:07 PM
    Moderator
  • I did. Same problem. I don't get it what is happening. It is something deeper than ordinary problems. 
    Tuesday, December 31, 2013 9:01 AM
  • Adding IP to connection string helped.
    • Marked as answer by Innspiron Tuesday, December 31, 2013 1:01 PM
    Tuesday, December 31, 2013 1:01 PM